The source code of MaintainSession.java: import java.io.* ; import javax.servlet.* ; import javax.servlet.http.* ; import java.util.* ; // for Date public class MaintainSession extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request,response) ; } // doPost public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html") ; PrintWriter out = response.getWriter() ; Furniture.doHeader(out,"Maintain a session") ; out.println("<p>This page is dynamically generated " +"by a Java servlet") ; // Get previously created session, or create new session if none exists HttpSession session = request.getSession() ; // Get accessCount attribute from session, or null if doesn't exist Integer accessCount = (Integer)session.getAttribute("accessCount") ; // Check the session status if (accessCount == null) { // No accessCount attribute, i.e. session just created? // Set up the new session accessCount = new Integer(1) ; session.setMaxInactiveInterval(60) ; out.println("<p>Session starts:") ; } else { // Increment the previously existing access count obtained from session accessCount = new Integer(accessCount.intValue()+1) ; out.println("<p>Session continues:") ; } // Add the atribute to the session session.setAttribute("accessCount",accessCount) ; // Finally, display interesting information about the session int maxInt = session.getMaxInactiveInterval() ; out.println("<p>Session ID : " + session.getId()) ; out.println("<br>Creation time : " + new Date(session.getCreationTime())) ; out.println("<br>Maximum inactive interval : " + maxInt + " seconds") ; if (accessCount.intValue() > 1) { out.println("<br>Last access time : " + new Date(session.getLastAccessedTime())) ; out.println("<br>Number of accesses : " + accessCount) ; } Furniture.doFooter(out) ; } // doGet } // class