摘要:站點的網(wǎng)站計數(shù)器的操作下午定義全局變量獲取計數(shù)器若文件存在則讀取獲取到文件的輸入流對計數(shù)器內(nèi)容進行加計數(shù)文件保存回文件流中輸入對象獲取文件路徑定義對象進行加您是第映射文件保存在文件夾下永遠無法訪問此時需要修改文件即可達到映
站點的網(wǎng)站計數(shù)器的操作
<%@ 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: ming
Date: 19-3-12
Time: 下午10:25
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title
<%
// 定義全局變量
BigInteger count = null;
%>
<%!
// 獲取計數(shù)器
public BigInteger load(File file){
BigInteger count = null;
try{
// 若文件存在則讀取
if(file.exists()){
Scanner scanner = null;
// 獲取到文件的輸入流
scanner = new Scanner(new FileInputStream(file));
// 對計數(shù)器內(nèi)容進行加1
if(scanner.hasNext()){
count = new BigInteger(scanner.next());
}
scanner.close();
}else{
count = new BigInteger("0");
save(file, count);
}
}catch (Exception e){
e.printStackTrace();
}
return count;
}
// 計數(shù)文件保存回文件
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%>
web映射
文件保存在WEB-INF文件夾下,永遠無法訪問,此時,需要修改/WEB-INF/web.xml文件即可,達到映射的目的
修改xml文件如下
Archetype Created Web Application he /WEB-INF/he.jsp he /hello
直接更新,但不重啟,發(fā)現(xiàn)不能加載.
此時.即Tomcat需要重寫配置屬性
此時訪問
http://localhost:8080/hello
即可訪問
config用于獲得
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://m.hztianpu.com/yun/73699.html
摘要:唯一的格式約束是該字符串必須用引號引起來。對于網(wǎng)站背后的服務(wù)器來說,不大相同。不過用戶不必忍受整個頁面的重新加載了,而且用戶在等待時,仍然可以響應(yīng)。 本篇是對《高性能網(wǎng)站建設(shè)指南》一書的后7種規(guī)則進行梳理。 八、使用外部Jacascript和css 1.如果需要呈現(xiàn)給用戶的頁面可以實現(xiàn)完整緩存,那么使用外部Jacascript和css會提高網(wǎng)站性能。 2.在使用使用外部Jacascr...
摘要:唯一的格式約束是該字符串必須用引號引起來。對于網(wǎng)站背后的服務(wù)器來說,不大相同。不過用戶不必忍受整個頁面的重新加載了,而且用戶在等待時,仍然可以響應(yīng)。 本篇是對《高性能網(wǎng)站建設(shè)指南》一書的后7種規(guī)則進行梳理。 八、使用外部Jacascript和css 1.如果需要呈現(xiàn)給用戶的頁面可以實現(xiàn)完整緩存,那么使用外部Jacascript和css會提高網(wǎng)站性能。 2.在使用使用外部Jacascr...
閱讀 1445·2021-11-24 09:38
閱讀 2159·2021-09-22 15:17
閱讀 2503·2021-09-04 16:41
閱讀 3631·2019-08-30 15:56
閱讀 3578·2019-08-29 17:19
閱讀 2030·2019-08-28 18:09
閱讀 1311·2019-08-26 13:35
閱讀 1785·2019-08-23 17:52