JSP using application statistics online number of methods _jsp programming

Source: Internet
Author: User

This article illustrates the way JSP uses application to count online numbers. Share to everyone for your reference.

The implementation methods are as follows:

Copy Code code as follows:
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title>application</title>

<body>
<%!
Integer number;//
synchronized void Numbervisiter ()
{
ServletContext application = Getservletcontext ();
Integer num = (integer) application.getattribute ("Count");
if (num = null)//If the first visitor
{
num = new Integer (1);
Application.setattribute ("Count", num);
}
Else
{
num = new Integer (Num.intvalue () + 1);
Application.setattribute ("Count", num);
}
}
%>
<%
if (Session.isnew ())
{
Numbervisiter ();
Integer number = (integer) application.getattribute ("Count");
}
%>
<p>
<font size= "2" color= "Blue" > Simple page Access counter </font>
</p>
<p>
<font size= "2" color= "#000000" >
Welcome to this page, you are <%=number%> access user
</font>
</p>
</body>

I hope this article will help you with the JSP program design.

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.