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 ??
How to get the HttpSession object ? The HttpServletRequest interface provides two methods to get the object of HttpSession: public HttpSession getSession():Returns the current session associated with this request, or if the request does not have a session, creates one.
TO get the value from session we use the getAttribute() method of HttpSession interface.
You can use Spring Session with HttpSession by adding a servlet filter before anything that uses the HttpSession . You can choose to do in any of the following ways: Java-based Configuration. XML-based Configuration.
Try:
@POST public String getData(Postdata postdata, @Context HttpServletRequest request) { HttpSession session = request.getSession(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With