This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Management" Watch "Session Management" New topic
Author

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) {
response.sendRedirect("login.jsp");
}

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
Greenhorn

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="http://www.amazon.com/exec/obidos/ASIN/067231939X/ref=ase_electricporkchop/107-2476442-4883722" 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: http://aspose.com/file-tools
 
subject: Session Management