Restful : How to get access to Httpsession inside

2020-05-24 20:28发布

I am using Jersey restful web services . This is my below code

@Path(/test)
public class testService  {
    @POST
    public String getData(Postdata postdata) {

    }

}

My question is , is it possible to get access to httpSession Object here in this class ??

标签: java rest jersey
2条回答
forever°为你锁心
2楼-- · 2020-05-24 20:42

Try:

@POST
public String getData(Postdata postdata, @Context HttpServletRequest request) {
  HttpSession session = request.getSession();
}
查看更多
女痞
3楼-- · 2020-05-24 20:56

If your service is NOT singleton, you can use:

@Path("/test")
public class TestResource  {

    @Context
    private HttpServletRequest request;

    @POST
    public String getData(Postdata postdata) {
        HttpSession session = request.getSession();
    }

}
查看更多
登录 后发表回答