session过期后,这段代码报空指针异常 如何修改

[code="java"] public String logoff() throws Exception {

    HttpSession session = request.getSession(false);

    session.removeAttribute("SE_SEIMEI");
    session.removeAttribute("SE_MAIL");
    session.removeAttribute(update_date);

    session.invalidate();

    id = null;
    mail = null;

    return "logoff";
}[/code]

[code="java"]

  1. public String logoff() throws Exception {

  2. HttpSession session = request.getSession(false);
  3.   if (null == session)
      {
          return "logoff";
      }  
    
  4. session.removeAttribute("SE_SEIMEI");  
    
  5. session.removeAttribute("SE_MAIL");  
    
  6. session.removeAttribute(update_date);  
    
  7. session.invalidate();  
    

    1. id = null;
    2. mail = null;

    3. return "logoff";
    4. }

[/code]

读取属性的时候报空指针吗?你在用它之前判断一下是否null 是的话(session超时、注销等) 你就给他跳转到登陆页面不就行了