Search code examples
javasessionjerseyjax-rshttpsession

Storing session objects in Jax-Rs Jersey


I am currently writing a web application using jersey-mvc and jersey-mvc-freemarker.

It is working fine , but I need a way to store session data.

On Servlets, I would use the HttpSession object, but I am wondering if there is a more JAX-RS-ish way to do it. Can someone please help?


Solution

  • In Jersey you can add HTTP Request to your context using injection:

    @Context
    private HttpServletRequest httpRequest;
    

    and then in method get HTTPSession object by:

    httpRequest.getSession()