所以返回才是null啊,有什么问题吗

解决方案 »

  1.   

    第一次访问的时候是没有count属性,所以要set一个初始值1;后面访问的时候,session已经有了count属性,就直接取值++。
    不知道有没有解决你的疑惑?
      

  2.   


    还没有session.setAttribute("count", count)就可以session.getAttribute("count")吗getAttribute可以在setAttribute之前吗
      

  3.   


    还没有session.setAttribute("count", count)就可以session.getAttribute("count")吗getAttribute可以在setAttribute之前吗
    没有该属性的时候,返回null
      

  4.   

    调用不分先后的,找了下tomcat的session实现类StandardSession
      public Object getAttribute(String name)
      {
        if (!isValidInternal()) {
          throw new IllegalStateException(sm.getString("standardSession.getAttribute.ise"));
        }    if (name == null) return null;    return this.attributes.get(name);
      }
    这样就比较清晰了