如下代码会得出什么样的结果,为什么呢
<%
Integer cnt=(Integer)application.getAttribute("hiscount");
if(cnt==null){
cnt=new Integer(1);
}else{
cnt=new Integer(cnt.intValue()+1);
}
application.setAttribute("hitcount",cnt);
 %>
 <%=cnt %>

解决方案 »

  1.   

    结果  cnt=1   输出1
    因为  一开始   你获取  application  是空的   进if
    将  cnt  设置为  new Integer(1)   
    就是  Integer cnt=new Integer(1);
    这时候  cnt的值就是  Integer类型的 1
    然后你 application.setAttibute("hitcount",cnt);
    只是将 cnt保存到 application中  这与cnt的值没有关系吧
    所以  cnt就等于1
    我试过了  确实如此
      

  2.   

    这个一般是记录页面访问次数的
    application的意思你明白吧?