您的位置:程序门 -> java -> web 开发



cookies记录登录次问题!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


cookies记录登录次问题![已结贴,结贴人:longjunf]
发表于:2007-01-09 11:24:37 楼主
我网站用了cookies记录登录次数!
首页index.jsp的cookies是这样写的:
<%
int   counter=0;
cookie   cookies[]=request.getcookies();
if(cookies!=null){
      for(int   i=0;i <cookies.length;i++){
              if(cookies[i].getname().equals( "counter "))
              counter=integer.parseint(cookies[i].getvalue())+1;
    }
}
cookie   c=new   cookie( "counter ", " "+counter);
c.setmaxage(60*60*12);
response.addcookie(c);
%>
<!--显示登录次数-->
<%
  if(counter==0){
        out.print( "欢迎首次光临! ");
}
else{
        out.print( "今天您已经光临了 "+counter+ "次! ");
        }
%>

其它页面other.jsp就这样写:
<%
int   counter=0;
cookie   cookies[]=request.getcookies();
if(cookies!=null){
      for(int   i=0;i <cookies.length;i++){
              if(cookies[i].getname().equals( "counter "))
              counter=integer.parseint(cookies[i].getvalue());
    }
}
%>  
<!--显示登录次数-->
<%
        if(counter==0){
        out.print( "欢迎首次光临! ");
}
else{
        out.print( "今天您已经光临了 "+counter+ "次! ");
        }
%>

问题就是这样:首页、其它页的登录次数不同步,特别是关了浏览器再打开时,首页跟其它页更是不同!怎么回事?用什么方法解决????
你们还有什么更好的记录登录次的程序吗?分享一下好不好^_^
发表于:2007-01-09 11:31:571楼 得分:20
用数据库表吧
发表于:2007-01-09 11:40:112楼 得分:0
用数据库表?
为每个仿问的用户都建一个表?
我不想这样,只是想它记录准确就行了


快速检索

最新资讯
热门点击