国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

一個可以防止刷新的JSP計數(shù)器

2019-11-18 21:55:47
字體:
供稿:網(wǎng)友
<%@ page contentType="text/html;charset=gb2312" %>
<!--jsp計數(shù)器-->
<%-- 以前學(xué)asp時,用ASP做防止刷新的計數(shù)器很簡單,以下是一個用JSP做的計數(shù)器--%>
<html>
<head>
<title>jsp計數(shù)器</title>
</head>
<body>
<%@ page import="java.io.*" %>
<%
//out.PRintln(request.getHeader("Cookie"));
String currentRecord = null;//保存文本的變量
BufferedReader file; //BufferedReader對象,用于讀取文件數(shù)據(jù)
String nameOfTextFile = "count.txt";

//讀取
file = new BufferedReader(new FileReader(nameOfTextFile));
String readStr =null;
int writeStr =0; //如果計數(shù)文本中的計數(shù)值為空則讓它顯示時變成1并寫入
try
{ readStr = file.readLine(); }
catch (IOException e)
{ System.out.println("讀取數(shù)據(jù)錯誤."); }
if (readStr == null) readStr = "沒有任何記錄";

//判斷cookie,第一次登陸時加1,刷新時不累計計數(shù)
else if (request.getHeader("Cookie")==null)
{ writeStr = Integer.parseInt(readStr)+1;}
else
{ writeStr = Integer.parseInt(readStr);}

//寫入時控制因為刷新引起的重復(fù)計數(shù)
if (request.getHeader("Cookie")==null)
{
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
pw.println(writeStr);
pw.close();}
catch(IOException e) {
out.println(e.getMessage());}
}
%>
<p align="center">您是CNJSP的第<b><font color="red"><%=writeStr%></font></b>位客人。</p>
</body>
</html>




上一篇:JSP技術(shù)簡介

下一篇:十三、JSP動作

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 沂源县| 宝鸡市| 尚义县| 梨树县| 榆林市| 明溪县| 正定县| 吴旗县| 德兴市| 治县。| 富源县| 平凉市| 洛浦县| 桃源县| 巧家县| 太仆寺旗| 司法| 涿鹿县| 奉贤区| 同仁县| 吉首市| 灵寿县| 襄汾县| 广宁县| 元氏县| 香河县| 景德镇市| 兰州市| 姜堰市| 呈贡县| 旬阳县| 板桥市| 汽车| 维西| 酒泉市| 运城市| 无棣县| 区。| 隆林| 正蓝旗| 明光市|