• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Management

 
Bharatesh H Kakamari
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Scott Stirling
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bharatesh H Kakamari
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all the valuable information. The author of this week's give-away has provided his view points
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic