Apache Struts 2 Documentation > Home > FAQs > How can we access request parameters passed into an Action |
You can obtain the request parameters by asking the ActionContext or implementing ParameterAware. Implementing ParameterAware is preferred.
The request parameters are available on the ActionContext instance, which is made available via ThreadLocal.
Map parameters = ActionContext.getContext().getParameters();
Preferred
Map parameters = this.getParameters();
When the servlet-config Interceptor sees that an Action implements ParameterAware, it passes a Map of the request parameters to the Action's setParameters method. |
To unit test a ParameterAware Action, create your own Map with the pertinent request parameters and call setParameters as part of the test's setUp method. |
@see struts-default.xml
@see org.apache.struts.action2.interceptor.ParameterAware
@see org.apache.struts.action2.interceptor.Servlet Config Interceptor