Example of Servlet access times

Source: Internet
Author: User

// ShowTimesServlet. java/* example of the number of visits implemented by Servlet! */
Import java. io .*;
Import java.util.zip .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
/*
The number of accesses implemented by this class. Show the number of visits! The number of visits!
*/
Public class ShowTimesServlet extends HttpServlet {

Public void doGet (HttpServletRequest request, HttpServletResponse response)
Throws ServletException, java. io. IOException {

Response. setContentType ("text/html ");
HttpSession session = request. getSession ();
String heading;
Integer access (favorite of small websites) Count = (Integer) session. getAttribute ("access (favorite of small websites) Count ");
If (access (favorite of small websites) Count = null ){
Access (favorite of small websites) Count = new Integer (0 );
Heading = "Welcom, You are first time to visit! ";
}
Else {
Heading = "Welcome Backer ";
Access (favorite of small websites) Count = new Integer (access (favorite of small websites) Count. intValue () + 1 );
}
Session. setAttribute ("access (favorite of small websites) Count", access (favorite of small websites) Count );
PrintWriter out = response. getWriter ();
Out. println ("The title:" + heading );
Out. println ("access (favorite of small websites) count:" + access (favorite of small websites) Count );
}

Public void doPost (HttpServletRequest request, HttpServletResponse response)
Throws ServletException, java. io. 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.