js| Display
Package Hall;
Import java.io.*;
Import javax.servlet.*;
Import javax.servlet.http.*;
Import java.net.*;
Import java.util.*;
Public class ShowSession extends HttpServlet {
public void doget (HttpServletRequest request,
HttpServletResponse response)
throws Servletexception, IOException {
HttpSession session = Request.getsession ( true);
Response.setcontenttype ("text/html");
PrintWriter out = Response.getwriter ();
String title = "Searching the Web";
String heading;
Integer accesscount = new Integer (0);;
if (session.isnew ()) {
Heading = "Welcome, newcomer";
} else {
heading = "Welcome back";
Integer Oldaccesscount =
//Use getattribute in servlet API 2.2 instead of GetValue
(integer) session.getvalue ("Accesscount ");
if (oldaccesscount!= null) {
Accesscount =
New Integer (Oldaccesscount.intvalue () + 1);
}
}
///Use Putattribute
Session.putvalue ("Accesscount", Accesscount) in servlet API 2.2;
Out.println (title) + Servletutilities.headwithtitle
"\n" +
"
" + heading + "
\ n" +
"
information on Your session:
\ n" +
"
\n" +"
\n" +"
Info Type |
value\n" + " |
\ n" +"
id\n" + " |
" + session.getid () + "\ n" + " |
\ n" +"
creation time\n" + " |
" + New Date (Session.getcreationtime ()) + "\ n" + " |
\ n" +"
time of last access\n" + " |
" + New Date (Session.getlastaccessedtime ()) + "\ n" + " |
\ n" +"
Number of Previous accesses\n" + " |
" + accesscount + "\ n" + " |
\ n" +
" ");
}
public void DoPost (HttpServletRequest request,
HttpServletResponse response)
Throws Servletexception, IOException {
Doget (request, response);
}
}