如下代码会得出什么样的结果,为什么呢
<%
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 %>
<%
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 %>
解决方案 »
- 求助:好像是jdom有错了~
- 创新创业项目
- java.lang.UnsatisfiedLinkError错误
- 在MVC2(例如 struts webwork)中如何使用OSCache缓存jsp?
- 求助一个关于JAVABEAN的问题,偶研究好几天了
- 刚找到工作,特来求教,tomcat+jBuilder+DB2如何配置整个开发系统,
- 谁知道用java代码对数据库批量更新怎么做?
- 为什么JBuilder中的servlet包里没有javax.servlet.jsp.tagext.*
- 急!急!急!关于发布后字体的问题......
- servlet 的小问题?
- 3个表的关联怎样写sql那?急,在线等!!!只有这么对分啦!!!
- 求教 正则表达式 全角空格的问题
因为 一开始 你获取 application 是空的 进if
将 cnt 设置为 new Integer(1)
就是 Integer cnt=new Integer(1);
这时候 cnt的值就是 Integer类型的 1
然后你 application.setAttibute("hitcount",cnt);
只是将 cnt保存到 application中 这与cnt的值没有关系吧
所以 cnt就等于1
我试过了 确实如此
application的意思你明白吧?