import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
out.println("<html>");
out.println("<head>");
out.println("<title>Simple Session Tracker</title>");
out.println("</head>");
out.println("<body>");
out.println("<h2>Session Info</h2>");
out.println("session Id: " + session.getId() + "<br><br>");
out.println( "The SESSION TIMEOUT period is " + session.getMaxInactiveInterval() + " seconds.<br><br>");
out.println( "Now changing it to 20 minutes.<br><br>");
session.setMaxInactiveInterval(20 * 60);
out.println("The SESSION TIMEOUT period is now " + session.getMaxInactiveInterval() + " seconds.");
out.println("</body>");
out.println("</html>");
}
/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
doGet(request,response);
}
}
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet><servlet-name>MyServletName</servlet-name>
<servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping><servlet-name>MyServletName</servlet-name>
<url-pattern>/index.html</url-pattern>
</servlet-mapping>
</web-app>
Download: ServletSessionInfo.zip( 89 k)