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 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
웹 사이트 빌더의 양식과 같은 본격적인 웹 사이트 빌더에서 과 같은 페이지 빌더, 과 같은 Link in Bio 빌더에 이르기까지 광범위한 웹 사이트 빌더를 살펴보면 네 가지 주요 사용자 양식과 조합을 관찰할 수 있습니다. 명령으로 블록...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.