Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session objects

 
sudha siva
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai All,

Can anyone explain me what is session objects.

Thanx
sudha
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Imagine yourself as the Bartender of this forum and people kept asking you questions, except, nobody is giving you their names. You wouldn't be sure who is asking what.
It would help to remember who is who if you can somehow give a unique token to each guy who posts a question. Then, when he comes back, he can show you the token you gave him, and since it's unique, you know exactly who he is. You can recognize him now.
HTTP is a stateless protocol and basically, a client makes a request, the server responds, and then that's it. If the same client makes a second request (like, clicking "Refresh", or whatever), the server has no way of knowing it was the same client before.
Unless the server gives the client a token.
A session object is an abstraction of this "token". It's the servlet's way of maintaining state (in the form of attributes) in a stateless protocol. In cruder terms, you can imagine a session object as a "shopping cart" of data that you load/unload (or more correctly bind/unbind) with setAttribute()/getAttribute() methods, as your client navigates through the JSPs and servlets of your web application.
For more information, I recommend you check the methods of the javax.servlet.http.HttpSession class in your Servlet API docs.
-anthony
 
aftab lal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
=============
when your servlet executes code
HttpSession ses=request.getSession();
The container creates the session object which
will only be available when you are using the
same browser and when you execute this servlet
by opening another browser new session object will
be created so session object is bind to browser.
==========
And you can place objects in HttSession Object by
sess.setAttribute("users",new Vector());
so it gives more controll over servlets.
=========
please can anyone correct me if i am wrong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic