Accessing HttpSession in PreProcessInterceptor

血红的双手。 提交于 2019-12-24 15:35:33

问题


Is it possible to access/create the HttpSession in the preProcess method of a PreProcessInterceptor?

(RestEasy 2.3.4)


回答1:


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...
}


来源:https://stackoverflow.com/questions/18211864/accessing-httpsession-in-preprocessinterceptor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!