在Struts 2拦截器中获取HttpServletRequest [英] Get HttpServletRequest in Struts 2 interceptor
本文介绍了在Struts 2拦截器中获取HttpServletRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要在拦截器中获取 HttpServletRequest
,我在下面使用代码:
To get the HttpServletRequest
in an interceptor I used below code:
HttpServletRequest request =(HttpServletRequest) ActionContext.getContext().get(HTTP_REQUEST);
我试图在拦截器中实现 ServletRequestAware
但它没有用。
I tried to implement ServletRequestAware
in the interceptor but it did not worked.
有没有更好的方法在拦截器中获得 HttpServletRequest
?
Are there any better ways to get HttpServletRequest
in an Interceptor ?!
推荐答案
您可以引用的servlet内容 servletConfig
拦截器。调用此拦截器后,您可以从 ServletActionContext
获取servlet内容。
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();
这篇关于在Struts 2拦截器中获取HttpServletRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文