还有,在开发环境中,Session是很容易失效的,一般情况下,什么样的错误会导致session失效!

解决方案 »

  1.   

    你用response.sendRedirect的时候,session失效
    应该在response.sendRedirect之前用java.lang.String response.encodeRedirectURL(java.lang.String url)方法encode url
    具体用法
    encodeRedirectURL
    public java.lang.String encodeRedirectURL(java.lang.String url)Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is seperate from the encodeURL method. 
    All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies. Parameters:
    url - the url to be encoded.
    Returns:
    the encoded URL if encoding is needed; the unchanged URL otherwise.
      

  2.   

    用session.setAttribute("name",Object)会好吧
    他好象试销的机会少点
    我的感觉
      

  3.   

    to reki(i feel love fly!):多谢,用这种方法还是没有解决问题。奇怪的是,在UNIX系统上没有出现这个问题。在NT上则有这个问题。
    to yanchang(笨笨):由于我们这中间保存的数据挺多,如果用这种形式太麻烦了。
      

  4.   

    NT只将jsp页定义成<jsp:useBean id="sessionBean" class="com.SessionBean" scope="session" />有问题的,我也遇到过
    解决办法是,将验证,写信息,读信息也时bean的*.java中即在你的com.SessionBean中首次登陆时做验证,成功后将信息写入session如
    HttpSession session;//成员变量
    String zgmc="";public void SetSession()
      {
        session.setMaxInactiveInterval(1000);//设置session时间属性
        session.setAttribute("zgmc", zgmc );
        ......
      }
      jsp取session的函数为
    void SetSession()
      {
        session.setAttribute("zgmc", zgmc );
        ......
      }
    public String getZgmc()
    {
    zgmc=session.getAttribute("zgmc").toString();//异常什么的要处理,我只简单提一下
    return zgmc;}
      

  5.   

    多copy了一个重复的
    void SetSession()
      {
        session.setAttribute("zgmc", zgmc );
        ......
      }