日期:2014-05-17  浏览次数:20769 次

JSP application的一个小问题
我的问题是:在网页中最后获得的结果是“欢迎访问本站,您是第 null 个访问用户。 ” 无论怎么弄数字都是null 应该怎么解决?
代码如下:  
<@ page contentType="text/html;charset=GB2312" %>
<HTML>
<head>
<title>网站计数器</title>
</head>
<BODY>
    <%!   
     synchronized void countPeople()//串行化计数函数
        {  ServletContext  application=getServletContext();
           Integer number=(Integer)application.getAttribute("Count");
           if(number==null)  //如果是第1个访问本站
              { number=new Integer(1);
                application.setAttribute("Count",number); 
              }
           else
              { number=new Integer(number.intValue()+1);
                application.setAttribute("Count",number); 
              }
        }
    %>
    <% if(session.isNew())//如果是一个新的会话
          countPeople();
       Integer yourNumber=(Integer)application.getAttribute("Count");
    %>
<P><P>欢迎访问本站,您是第
    <%=yourNumber%>
个访问用户。
</BODY>
</HTML>


跪求各位大神帮助!!!
------解决方案--------------------
如果代码没错的话,在if后面加个else,在else里面随便给yournumber一个值,看看值出不出来
------解决方案--------------------
总是觉得application.getAttribute("Count")  这样是取不出的。。
------解决方案--------------------
你的编译器不报错?!
<@ page contentType="text/html;charset=GB2312" %>   少个%
<P><P>欢迎访问本站,您是第<%=yourNumber%>个访问用户。 少2个</p>