日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

网站计数器 web映射

發布時間:2023/12/6 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 网站计数器 web映射 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

站點的網站計數器的操作

<%@ page import="java.math.BigInteger" %> <%@ page import="java.io.File" %> <%@ page import="java.util.Scanner" %> <%@ page import="java.io.FileInputStream" %> <%@ page import="java.io.PrintStream" %> <%@ page import="java.io.FileOutputStream" %> <%@ page import="java.util.zip.InflaterOutputStream" %><%--Created by IntelliJ IDEA.User: mingDate: 19-3-12Time: 下午10:25To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>Title</title> </head> <body> <%// 定義全局變量BigInteger count = null; %> <%!// 獲取計數器public BigInteger load(File file){BigInteger count = null;try{// 若文件存在則讀取if(file.exists()){Scanner scanner = null;// 獲取到文件的輸入流scanner = new Scanner(new FileInputStream(file));// 對計數器內容進行加1if(scanner.hasNext()){count = new BigInteger(scanner.next());}scanner.close();}else{count = new BigInteger("0");save(file, count);}}catch (Exception e){e.printStackTrace();}return count;}// 計數文件保存回文件public void save(File file, BigInteger count){try{PrintStream printStream = null;printStream = new PrintStream(new FileOutputStream(file));// 流中輸入對象printStream.println(count);printStream.close();}catch (Exception e){e.printStackTrace();}} %> <%// 獲取文件路徑String fileName = this.getServletContext().getRealPath("/") + "count.txt";// 定義file對象File file = new File(fileName);// 進行加if(session.isNew()) {synchronized (this) {count = load(file);System.out.println(count);count = count.add(new BigInteger("1"));save(file, count);}} %> 您是第<%=count%> </body> </html>

web映射

文件保存在WEB-INF文件夾下,永遠無法訪問,此時,需要修改/WEB-INF/web.xml文件即可,達到映射的目的
修改xml文件如下

<!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app><display-name>Archetype Created Web Application</display-name><servlet><servlet-name>he</servlet-name><jsp-file>/WEB-INF/he.jsp</jsp-file></servlet><servlet-mapping><servlet-name>he</servlet-name><url-pattern>/hello</url-pattern></servlet-mapping> </web-app>

直接更新,但不重啟,發現不能加載.
此時.即Tomcat需要重寫配置屬性
此時訪問
http://localhost:8080/hello
即可訪問

config

config用于獲得

總結

以上是生活随笔為你收集整理的网站计数器 web映射的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。