DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
You can obtain the request by asking the ActionContext or implementing ServletResponseAware. Implementing ServletResponseAware is preferred.
Ask the ActionContext
The response is available on the ActionContext instance, which is made available via ThreadLocal.
HttpServletResponse response = ServletActionContext.getResponse();
Implement ServletResponseAware
Preferred
- Ensure that
servlet-configInterceptor is included in the Action's stack.The default stack already includes
servlet-config.
- Edit the Action so that it implements the ServletResponseAware interface.
- The ServletResponseAware interface expects a
setServletResponsemethod. You may wish to include a companiongetServletResponsemethod.
- The ServletResponseAware interface expects a
- At runtime, call
getServletResponseto obtain a reference to the response object.When the
servlet-configInterceptor sees that an Action implements ServletResponseAware, it passes a reference to the request the Action'ssetServletResponsemethod.@see struts-default.xmlIt is more difficult to test Actions with runtime dependencies on HttpServletReponse. Only implement ServletResponseAware as a last resort. A better approach to solving a use case involving the response may be with a custom Result Type.
@see org.apache.struts.action2.interceptor.ServletResponseAware
@see org.apache.struts.action2.interceptor.ServletConfigInterceptor