请教怎么让计数器防止刷新??? 你在页面中赋一个初值给Session。然后在页面中对session进行判断。如果她已经存在就不计数。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先看一下该ip地址的session有没有访问,若无,则加一;有,怎不加。String userIp=(String)session.getValue("userip");if(userIp==null){ 计数器加一; String UserIp=request.getRemoteAddr(); session.putValue("userip",UserIp); String strCount = "" ;if(session.getAttribute("count")==null){ int count = 0 ; File f = new File((request.getRealPath("/"))+"\\count\\count.txt"); BufferedReader br = new BufferedReader(new FileReader(f)); strCount=br.readLine() ; count=Integer.parseInt(strCount)+1; strCount=(new Integer(count)).toString(); PrintWriter pw = new PrintWriter(new FileWriter(f)) ; pw.println(strCount); pw.close(); session.setAttribute("count",strCount);}else{ strCount = session.getAttribute("count").toString();}把计数器改成这样就行了。///////如何防止用户更新页面刷新计数器! 一个用户session过期后,为什么其他用户都无法登录 急急急~~~jsp页面的jpg图片右键另存问题 hibernate分页 B/S系统集成C/S系统的问题 关于JSP的数据库结果集的操作问题, 三层架构和设计模式在什么场合下运用? 初学者请教:我写了个JSP数据记录集分页,总是提示NoSuchMethodError错误 帮我看看是不是我的环境变量的配置问题 Invalid operation for the current cursor position.是什么异常? 刚开发完一个网站,大家给点意见:-) 在jsp中如何判断传来的字符串是8859-1编码还是gb2312编码方式 求助!!
String userIp=(String)session.getValue("userip");
if(userIp==null){
计数器加一;
String UserIp=request.getRemoteAddr();
session.putValue("userip",UserIp);
if(session.getAttribute("count")==null)
{
int count = 0 ;
File f = new File((request.getRealPath("/"))+"\\count\\count.txt");
BufferedReader br = new BufferedReader(new FileReader(f));
strCount=br.readLine() ;
count=Integer.parseInt(strCount)+1;
strCount=(new Integer(count)).toString();
PrintWriter pw = new PrintWriter(new FileWriter(f)) ;
pw.println(strCount);
pw.close();
session.setAttribute("count",strCount);
}
else
{
strCount = session.getAttribute("count").toString();
}
把计数器改成这样就行了。///////如何防止用户更新页面刷新计数器!