Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
208
Chapter 9 Session Tracking
Listing 9.1 ShowSession.java (continued)
(Integer)session.getValue("accessCount");
if (accessCount == null) {
accessCount = new Integer(0);
heading = "Welcome, Newcomer";
} else {
heading = "Welcome Back";
accessCount = new Integer(accessCount.intValue() + 1);
}
// Use setAttribute instead of putValue in version 2.2.
session.putValue("accessCount", accessCount);
out.println(ServletUtilities.headWithTitle(title) +
"\n" +
"" + heading + "
\n" +
"Information on Your Session:
\n" +
"\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
\n" + "
Info Type | Value\n" +
" |
ID\n" +
" | " + session.getId() + "\n" +
" |
Creation Time\n" +
" | " +
new Date(session.getCreationTime()) + "\n" +
" |
Time of Last Access\n" +
" | " +
new Date(session.getLastAccessedTime()) + "\n" +
" |
Number of Previous Accesses\n" +
" | " + accessCount + "\n" +
" |
\n" +
"");
}
/** Handle GET and POST requests identically. */
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved