直接判断session == null不行,因为当session.invalidate()后,session不为null

解决方案 »

  1.   

    HttpSession session = request.getSession(true);
    if (session.isNew()){
      以前的session失效
    }
      

  2.   

    ZeroC(笨小孩) 的方法不通用
      

  3.   

    为了限制用户非法登陆,我写了一个include文件,内容:
    if (session.getAttribute("userName") == null) {
        response.sendRedirect("/jsp/error.jsp?errorId=1");
    }
    为了使这个文件能用于任何系统里,就不能对session.getAttribute("userName")进行判断,因为不同的系统中用户登陆时设置的session中的参数不同
      

  4.   

    为了限制用户非法登陆,我写了一个include文件,内容:
    if (session.getAttribute("userName") == null) {
        response.sendRedirect("/jsp/error.jsp?errorId=1");
    }
    为了使这个文件能用于任何系统里,就不能对session.getAttribute("userName")进行判断,因为不同的系统中用户登陆时设置的session中的参数不同
     
    "为了使这个文件能用于任何系统里",这句话,不明白什么意思?什么叫任何系统?是指操作系统?为什么不同的系统中用户登陆时设置的session中的参数不同,能解释一下吗?
      

  5.   

    public void invalidate()Invalidates this session then unbinds any objects bound to it.
    Throws:
    IllegalStateException - if this method is called on an already invalidated session//利用这个试试,就是有点浪费资源try
    {
        session.invalidate();
    }
    catch(IllegalStateException e)
    {
        response.sendRedirect("/jsp/error.jsp?errorId=1");
    }