File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Session Management Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Management" Watch "Session Management" New topic

Session Management

Bharatesh H Kakamari
Ranch Hand

Joined: Nov 09, 2000
Posts: 198
Can any one post examples for various Session Management techniques followed in servlets.
1. session api
2. url rewriting
3. hidden fields
4. Cookies
5. basic authentication
Geoff Tate
Ranch Hand

Joined: Feb 06, 2001
Posts: 55
For the session api you would use the HttpSession.putValue() and HttpSession.getValue() methods to pull objects in and out of the session. The way this usualluy works is that a cookie (that is not persisted to the local drive) is sent back and forth from the browser with each request/response. This cookie contains a session id that is generated by your java server engine:
in a jsp, heres how you usually start a new session for a user - usually for an application that requires login/logout
session.invalidate(); // this removes all session info
session = request.getSession(true); // creates new session\
// now you can use session.putValue(), session.getValue()

session.putValue("validated", "true");
if (session.getValue("validated")) == null) {

not the most useful example, but I think you see the point.

<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR> fantastic, a towel? <HR></BLOCKQUOTE>
Scott Stirling

Joined: Mar 05, 2001
Posts: 24
Side note: getValue() and putValue() have been deprecated in favor of getAttribute() and setAttribute() as of Servlet 2.2 API.
Scott Stirling
Author of Java Server Pages Application Development

Scott Stirling<BR>Author of <A HREF="" TARGET=_blank rel="nofollow">Java Server Pages Application Development</A>
Bharatesh H Kakamari
Ranch Hand

Joined: Nov 09, 2000
Posts: 198
Thanks all the valuable information. The author of this week's give-away has provided his view points
I agree. Here's the link:
subject: Session Management
It's not a secret anymore!