Restful : How to get access to Httpsession inside the Service class?

后端 未结 2 1516
别那么骄傲
别那么骄傲 2021-02-05 02:52

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

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


        
相关标签:
2条回答
  • 2021-02-05 03:07

    Try:

    @POST
    public String getData(Postdata postdata, @Context HttpServletRequest request) {
      HttpSession session = request.getSession();
    }
    
    0 讨论(0)
  • 2021-02-05 03:12

    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();
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题