In my web services class using(jersey) @Context
I injected HttpServletRequest
, HttpServletResponse
, ServletContext
objects for authentication i called a ValidateUser
servlet.
@Path("/server")
public class WebServer {
@Context
private ServletContext context;
@Context
private HttpServletRequest request;
@Context
private HttpServletResponse response;
@POST
@Path("/auth")
@Consumes(MediaType.APPLICATION_JSON)
public Response createTrackInJSON(Track track) throws IOException, ServletException{
....
context.getRequestDispatcher("/ValidateUser")include(request, response);
...
}
}
in ValidateUser.java i created session after validations as:
HttpSession session = request.getSession(true);
Up to now everything is working fine but when I call:
HttpSession session = request.getSession(false);
session.invalidate();
in Logout Servlet session is null
. I know restful web services are stateless but i need to maintain session at server side is there any way i can achieve this? What about @PerSession
annotation? Will it be useful in this scenario?