import java.io.PrintWriter;
import java.io.IOException;
import java.util.Date;
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 SessionTracker extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
HttpSession session = req.getSession(true);
Integer count = (Integer) session.getAttribute("count");
if (count == null) {
count = new Integer(1);
} else {
count = new Integer(count.intValue() + 1);
}
session.setAttribute("count", count);
out.println("SessionSnoop");
out.println("Session Details
");
out.println("You've visited this page " + count + ((count.intValue()== 1) ? " time." : " times.") + "
");
out.println("Details of this session:
");
out.println("Session id: " + session.getId() + "
");
out.println("New session: " + session.isNew() + "
");
out.println("Timeout: " + session.getMaxInactiveInterval() + "
");
out.println("Creation time: " + new Date(session.getCreationTime()) + "
");
out.println("Last access time: " + new Date(session.getLastAccessedTime()) + "
");
out.println("");
}
}
SessionAttributes.zip( 89 k)