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 ?!
You need to use ActionInvocation#getInvocationContext()
to retrieve your request.
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext context = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);
// ...
}
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();
use
final HttpServletRequest request = (HttpServletRequest) ActionContext.getContext()
.get(ServletActionContext.HTTP_REQUEST);
it worked for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With