This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Servlets and the fly likes Session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session" Watch "Session" New topic


Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163

Please clarrify my doubts..

1. when can we use URL writting, hidden fields, cookies and HttpSession to handle session?

2. if the client disabled the cookies, what will happen to the session? how can we handle the session if the client disabled the cookies?

3. is HttpSession uses Cookies ?

thanks ,
Thennam Pandian.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

1) By default only cookies will be used. Some servers need to to be configured to allow URL rewriting. Hidden fields are not supported by default, and I have never seen them used in Java.

2) If the client 'disables cookies', cookie based sessions may or may not work depending on what they allow. By default session cookies are stored in-memory and not written to the hard drive. In some cases these in-memory cookies will still be allowed but persistent cookies will not.

3) by default sessions use cookies.
Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163

Thank you for your reply.

if the cookies are stored in server side memory, how the server will recognize the request( whether is it a new request or a old request?)
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Cookies are never stored on the server.
They are always stored on the client.

Session data is stored on the server.
The only thing stored in the cookie is the sessionID.
This, to answer your question, is how the server knows which client initiated each request and is used to match up the client with their session.
[ May 02, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Thanks now i understood Cookies and session ....
dna network

Joined: May 02, 2008
Posts: 1
use session..very use....nice & smooth..

// Create Session...


// Retrive Back ..

variable_name = session.getAttribute("session_name").toString();
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Also, the original poster wasn't asking how to use sessions.
He was asking how they work.

From the looks of his last post, it appears that his question was answered.

Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
I wrote a small servlet to validate my understanding in reference to your question. Posting its code, maybe it helps:

Thanks and Regards
Have you checked out Aspose?
subject: Session
jQuery in Action, 3rd edition