Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

rest

jersey

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 ??

like image 369
Pawan Avatar asked Aug 06 '12 15:08

Pawan


People also ask

How do I find HttpSession?

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.

Which method of the HttpSession interface is used to retrieve an attribute from the session?

TO get the value from session we use the getAttribute() method of HttpSession interface.

Can we use HttpSession in spring boot?

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.


1 Answers

Try:

@POST public String getData(Postdata postdata, @Context HttpServletRequest request) {   HttpSession session = request.getSession(); } 
like image 184
condit Avatar answered Sep 19 '22 15:09

condit