Search code examples
struts2struts2-interceptorsactioncontext

Get HttpServletRequest in Struts 2 interceptor


To get the HttpServletRequest in an interceptor I used below code:

HttpServletRequest request =(HttpServletRequest) ActionContext.getContext().get(HTTP_REQUEST);

I tried to implement ServletRequestAware in the interceptor but it did not worked.

Are there any better ways to get HttpServletRequest in an Interceptor ?!


Solution

  • The servlet stuff you could get referencing servletConfig interceptor. After this interceptor is invoked you could get servlet stuff from ServletActionContext.

    HttpServletRequest request = ServletActionContext.getRequest();