jersey security and session management

前端 未结 7 1022
甜味超标
甜味超标 2020-11-29 16:53

Is there a way to get session management or security programatically in Jersey, e.g. web-application session management? Or are transactions, sessions, and security all han

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 17:23

    Session management is the purview of the container in which Jersey is deployed. In most production cases, it will be deployed within a container that performs session management.

    The code below is a simple example of a jersey resource that gets the session object and stores values in the session and retrieves them on subsequent calls.

    @Path("/helloworld")
    public class HelloWorld {
    
        @GET
        @Produces("text/plain")
        public String hello(@Context HttpServletRequest req) {
    
            HttpSession session= req.getSession(true);
            Object foo = session.getAttribute("foo");
            if (foo!=null) {
                System.out.println(foo.toString());
            } else {
                foo = "bar";
                session.setAttribute("foo", "bar");
            }
            return foo.toString();
    
    
        }
    }
    

提交回复
热议问题