import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
HttpSession session = req.getSession();
Integer count = (Integer)session.getAttribute("snoop.count");
if (count == null)
count = new Integer(1);
else
count = new Integer(count.intValue() + 1);
session.setAttribute("snoop.count", count);
out.println("SessionSnoop ");
out.println("Session Snoop
");
out.println("You've visited this page " + count +
((count.intValue() == 1) ? " time." : " times."));
out.println("");
out.println("
Here is your saved session data:
");
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
out.println(name + ": " + session.getAttribute(name) + "
");
}
out.println("Here are some vital stats on your session:
");
out.println("Session id: " + session.getId() +
" (keep it secret)
");
out.println("New session: " + session.isNew() + "
");
out.println("Timeout: " + session.getMaxInactiveInterval());
out.println("(" + session.getMaxInactiveInterval() / 60 +
" minutes)
");
out.println("Creation time: " + session.getCreationTime());
out.println("(" + new Date(session.getCreationTime()) + ")
");
out.println("Last access time: " + session.getLastAccessedTime());
out.println("(" + new Date(session.getLastAccessedTime()) +
")
");
out.println("Requested session ID from cookie: " +
req.isRequestedSessionIdFromCookie() + "
");
out.println("Requested session ID from URL: " +
req.isRequestedSessionIdFromURL() + "
");
out.println("Requested session ID valid: " +
req.isRequestedSessionIdValid() + "
");
out.println("Test URL Rewriting
");
out.println("Click res.encodeURL(req.getRequestURI()) + "\">here");
out.println("to test that session tracking works via URL");
out.println("rewriting even when cookies aren't supported.");
out.println("");
}
}
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
MyServletName
MyServlet
MyServletName
/index.html