SoFunction
Updated on 2025-03-08

JSP method to use application to count online users

<%@ page language="java" import=".*" pageEncoding="UTF-8"%>
<%
String path = ();
String basePath = ()+"://"+()+":"+()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title>application</title>
  </head>
  
  <body>
  <%!
Integer number;//
synchronized void numberVisiter()
{
ServletContext application = getServletContext();
Integer num = (Integer)("count");
if(num == null)//If it is the first visitor
{
num = new Integer(1);
("count",num);
}
else
{
num = new Integer(() + 1);
("count",num);
}
}
  %>
  <%
  if(())
  {
  numberVisiter();
  Integer number = (Integer)("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 a <%=number%> visitor user
  </font>
  </p>
  </body>
</html>