JSP Display session Information instance

Source: Internet
Author: User
Tags date integer string
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" +" \ n" +" \ n" +" \ n" +" \ n" +"
Info Type value\n" +
"
id\n" +
"
" + session.getid () + "\ n" +
"
creation time\n" +
"
" + New Date (Session.getcreationtime ()) + "\ n" +
"
time of last access\n" +
"
" + New Date (Session.getlastaccessedtime ()) + "\ n" +
"
Number of Previous accesses\n" +
"
" + accesscount + "\ n" +
"
\ n" +
" ");
}
public void DoPost (HttpServletRequest request,
HttpServletResponse response)
Throws Servletexception, IOException {
Doget (request, response);
}
}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.