File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session" Watch "Session" New topic
Author

Session

Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Hi,

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
Rancher

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
Hi,

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
Sheriff

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
Greenhorn

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

// Create Session...

session.setAttribute("session_name",variable_name);

// Retrive Back ..

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

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.


-Ben
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session
 
Similar Threads
does request.getSession().setAttribute work if cookies disabled
Storing Objects URGENT
Cookies and session !
Kindly clarify "HttpSession.isNew()"
Doubts on Cookie..