A simple website counter
9707 단어 website
About the application object: The application object is used to share data between multiple programs or multiple users. The application object used by the user is the same. This is different from the session. Once the server is started, the application object will be automatically created and kept forever Go down until the server shuts down and the application object disappears automatically. The following is to use the application object to implement a website counter, the code is as follows:
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3 <html>
4 <body>
5 <%!
6 synchronized void count(){ // sychronized ,
7 // .
8 ServletContext application = ((HttpServlet)(this)).getServletContext();
9 Integer count = (Integer)application.getAttribute("count");
10
11 if(count==null){
12 count = new Integer(1);
13 application.setAttribute("count",count);
14 }else{
15 count = new Integer(count.intValue()+1);
16 application.setAttribute("count",count);
17 }
18 }
19 %>
20
21 <%
22 if(session.isNew()){ // .
23 count();
24 out.println(" "+application.getAttribute("count")+" ");
25 }
26 %>
27 </body>
28 </html>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Top Web Application Development Trends in 2017But to attract people and to pace up with the changing trends web developers have a difficult challenge. This challenge ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.