Reputation: 169
I have a servlet ,it creates the session and I need to pass that session to another servlet, Is that possible ?
Upvotes: 1
Views: 805
Reputation: 1565
Yes you can.
Sessions are not specific to a servlet it is managed by your servlet container.
So even if you forward request from one servlet to another and use request.getSession()
the session will persist, provided you dont call the invalidate()
or session timeout
didn't occurs and both the servlets belong to same web application.
To add on :
When the first request comes from a user he is assigned a session and all further request\response will have in same session unless the session expires either due to session timeout or invalidate()
method was called. The container manages session with two methods:
Upvotes: 1