jsp计数器代码
jsp计数器代码
发布时间:2016-12-29 来源:查字典编辑
摘要:

<>

<%

BufferedReader inf = new BufferedReader(new FileReader("/path/to/counter.txt"));

int tmp = Integer.parseInt(inf.readLine());

int i=0;

try {

i = Integer.parseInt(request.getSession().getValue("tal").toString());

} catch (NullPointerException t) {i=0; }

if (i==0) {

tmp++;

PrintWriter outf = new PrintWriter(new BufferedWriter(new FileWriter("/path/to/counter.txt")));

outf.println(tmp);

outf.close();

inf.close();

request.getSession().putValue("tal", "1");

}

BufferedReader inf2 = new BufferedReader(new FileReader("/path/to/counter.txt"));

%>

<%

String zeroes="";

String hits = inf2.readLine();

inf2.close();

for (int t=0; t < 8-hits.length(); t++) {

zeroes=zeroes+"0"; }

out.println(zeroes + hits);

%>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新JSP教程学习
热门JSP教程学习
编程开发子分类