import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class SessionTimer extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
HttpSession session = req.getSession();
out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>");
out.println("<BODY><H1>Session Timer</H1>");
out.println("The previous timeout was " + session.getMaxInactiveInterval());
out.println("<BR>");
session.setMaxInactiveInterval(2 * 60 * 60); // two hours
out.println("The newly assigned timeout is " + session.getMaxInactiveInterval());
out.println("</BODY></HTML>");
}
}
|