在 PreProcessInterceptor 中访问 HttpSession [英] Accessing HttpSession in PreProcessInterceptor
本文介绍了在 PreProcessInterceptor 中访问 HttpSession的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在PreProcessInterceptor
的preProcess
方法中访问/创建HttpSession
?
Is it possible to access/create the HttpSession
in the preProcess
method of a PreProcessInterceptor
?
(RestEasy 2.3.4)
(RestEasy 2.3.4)
推荐答案
您可以通过使用 @Context
注入 HttpServletRequest
来访问 HttpSession
> 注释,然后从请求中获取会话,如下所示:
You can access the HttpSession
by injecting the HttpServletRequest
using the @Context
annotation and then getting the session from the request like so:
@Context
private HttpServletRequest servletRequest;
@Override
public ServerResponse preProcess(HttpRequest request, ResourceMethod method)
throws Failure, WebApplicationException
{
HttpSession session = servletRequest.getSession();
//Do something with the session here...
}
这篇关于在 PreProcessInterceptor 中访问 HttpSession的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文