user460920
user460920

Reputation: 887

Sessions in servlets are maintained where?

In Servlets we can use the feature of Session Tracking. So i want to just ask that the sessions are maintained onto the clientside or on serverside.

If it's on clientside then where?
Can i create session on the clientside HTTPSession?

I found one article which tells that sessions on clientside as well as serverside can be maintained.

Upvotes: 4

Views: 3289

Answers (2)

Ramesh PVK
Ramesh PVK

Reputation: 15446

It is the server which will maintain the sessions. And it is the server responsibilty to allow session tracking happen. Clients need not bother about sending any information explicitly. As Client can sends Cookies saved on the client along with every request, server might use Cookies for sesssion tracking.

Note: Cookies are just one of the way to implement Session Tracking. It is also the best way

So server uses Cookies as one of the ways to handle session tracking.

It can also be done in other ways:

URL rewriting - the application/server should append the session id in all URL's/Links. When those are invoked from the client the session comes to the server along with the URL.

Hidden Form Fields - The forms may contain hidden input type with session id as field value. When the form is posted, the session id comes along with the form data.

Upvotes: 3

Jigar Joshi
Jigar Joshi

Reputation: 240890

Session resides on server side on client side we have cookie (or jsessionId or hidden form fields) to map the request with server's session


How it maps

When you submit a request for the first time( from the beginning of the time), server gives you a cookie with response they send your browser accepts that cookie it contains the expiry date, content (some String), and domain name now when you send the request again to server your browser will add that cookie for that domain in header so when server receives the request it sees the cookie from header and maps that content with sessionId on server


FYI

You can also have session in other applications (for example peer-peer app)

Upvotes: 3

Related Questions