Accessing HttpSession in PreProcessInterceptor

2019-08-12 03:51发布

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

(RestEasy 2.3.4)

1条回答
何必那么认真
2楼-- · 2019-08-12 04:10

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...
}
查看更多
登录 后发表回答