在某种意外情况下。此session非彼session,加入isnew(),来判断session是否是此session。我在这里说得不知道对不对,请大家继续发表。

解决方案 »

  1.   

    isNew
    public boolean isNew()Returns true if the client does not yet know about the session or if the client chooses not to join the session. For example, if the server used only cookie-based sessions, and the client had disabled the use of cookies, then a session would be new on each request.
    Returns:
    true if the server has created a session, but the client has not yet joined
    Throws:
    java.lang.IllegalStateException - if this method is called on an already invalidated session
    以上是J2EE文档的官方说明。
    个人理解为:
       第一次打开注册页面,Session为NEW,IF(!Session.isNew())里面的内容就没有必要执行。也不用反馈信息,所以
      

  2.   

    第一次访问时,session isNew() 返回true,只显示表单信息!
    递交表单之后,session.isNew() 为false 做相应的处理!不过这样做弊端很大,这个程序不能用!你可以考虑一下,为什么不能用!嘿嘿!
      

  3.   

    Returns true if the client does not yet know about the session or if the client chooses not to join the session. For example, if the server used only cookie-based sessions, and the client had disabled the use of cookies, then a session would be new on each request.
    Returns:
    true if the server has created a session, but the client has not yet joined
    Throws:
    java.lang.IllegalStateException - if this method is called on an already invalidated session个人认为:用来防止恶意注册,也就是说如果client(客户端)登陆到本站点--〉此时session才能被创建,才可以进行相应的注册。相反,如果哪位仁兄闲着没事自己写个客户端的程序来到你的站点上注册玩(这时session并不能被创建)那可就不太好了,所以加上对session是否是刚刚创建的判断可以防止恶意注册!(个人认为,仅作参考)