Here is a simple servlet program which display session information.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class sessionInfo extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
HttpSession mySession = req.getSession(true);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><BODY>");
out.println("<h3>Session Information</H3>");
out.println("<BR>New Session : " + mySession.isNew());
out.println("<BR>Session ID : " + mySession.getId());
out.println("<BR>Session Creation Time : " + mySession.getCreationTime());
out.println("<BR>Session Last Accessed Time : " + mySession.getLastAccessedTime());
out.println("<BR><H3>Request Information</H3>");
out.println("<BR>Session ID from Request : " + req.getRequestedSessionId());
out.println("<BR>Session ID via Cookie : " + req.isRequestedSessionIdFromCookie());
out.println("<BR>Valid Session ID : " + req.isRequestedSessionIdValid());
out.println("</BODY></HTML>");
out.close();
}
}
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class sessionInfo extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
HttpSession mySession = req.getSession(true);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><BODY>");
out.println("<h3>Session Information</H3>");
out.println("<BR>New Session : " + mySession.isNew());
out.println("<BR>Session ID : " + mySession.getId());
out.println("<BR>Session Creation Time : " + mySession.getCreationTime());
out.println("<BR>Session Last Accessed Time : " + mySession.getLastAccessedTime());
out.println("<BR><H3>Request Information</H3>");
out.println("<BR>Session ID from Request : " + req.getRequestedSessionId());
out.println("<BR>Session ID via Cookie : " + req.isRequestedSessionIdFromCookie());
out.println("<BR>Valid Session ID : " + req.isRequestedSessionIdValid());
out.println("</BODY></HTML>");
out.close();
}
}
No comments:
Post a Comment