You can obtain the request parameters by asking the ActionContext or implementing ParameterAware. Implementing ParameterAware is preferred.
Ask the ActionContext
The request parameters are available on the ActionContext instance, which is made available via ThreadLocal.
Code Block |
---|
Map parameters = ActionContext.getContext().getParameters();
|
Implement HttpParametersAware
Preferred
- Ensure that
servlet-config
Interceptor is included in the Action's stack.- The default stack already includes
servlet-config
.
- The default stack already includes
- Edit the Action so that it implements the HttpParametersAware interface.
- The HttpParametersAware interface expects a
setParameters
method. You may wish to include a companiongetParameters
method.
- The HttpParametersAware interface expects a
- At runtime, call
getParameters
to obtain an object representing the request parameters.
Info |
---|
When the |
see struts-default.xml and org.apache.struts.action2
Method A:
ActionContext.getParameters() (returns Map, works internally using a ThreadLocal)
Method B:
Have the action implements ParameterAware interface and the parameters will be set through the setParameters(Map) method. This requires that the 'servlet-config' interceptor being added to that particular action.
@see webwork-default.xml
@see com.opensymphony.webwork.interceptor.ParameterAware
@see com.opensymphony.webwork.interceptor.Servlet Config Interceptor