HttpSession Methods 
(Continued)
isNew 
Determines if session is new to client (not to page)
getCreationTime
Returns time at which session was first created 
getLastAccessedTime 
Returns time session was last sent from client 
getMaxInactiveInterval,
setMaxInactiveInterval 
Gets or sets the amount of time session should go without 
access before being invalidated 
invalidate 
Invalidates the session and unbinds all 
objects associated with it
91
Servlets
www.corewebprogramming.com
A Servlet Showing Per Client 
Access Counts
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Session Tracking Example";
HttpSession session = request.getSession(true);
String heading;
Integer accessCount =
(Integer)session.getAttribute("accessCount");
if (accessCount == null) {
accessCount = new Integer(0);
heading = "Welcome, Newcomer";
} else {
heading = "Welcome Back";
accessCount = new Integer(accessCount.intValue() + 1);
}
session.setAttribute("accessCount", accessCount);
92
Servlets
www.corewebprogramming.com
46




  

Home

About Services Network Support FAQ Order Contact
 

Servlet Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved