title: NullPointerException of my SESSION in STRUTS2
body: <p>After the user logged-in, the user's session is added. And when a user clicks Logout,
  it first goes through the interceptor before the action. I don't understand why my session is null after it bypasses my CacheInterceptor.  </p>
  
  <p>CacheInterceptor's purpose is to avoid user to click the back button after he log's off in the application.  </p>
  
  <p>Given this following codes:  </p>
  
  <p><strong>welcome.jsp</strong>  </p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=US-ASCII"
  pageEncoding="US-ASCII"%&gt;
  &lt;%@ taglib uri="/struts-tags" prefix="s"%&gt;
  &lt;%if(session.getAttribute("USER") == null){%&gt; &lt;jsp:forward page="login.html"/&gt; &lt;%}%&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"&gt;
  &lt;title&gt;Welcome Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h3&gt;Welcome &lt;s:property value="userName"&gt;&lt;/s:property&gt;&lt;/h3&gt;
  
  &lt;form action="logout" method="post"&gt;
  &lt;input value="Logout" type="submit" name="ibm-submit" class="ibm-btn-arrow-pri" /&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;  
  </code></pre>
  
  <p><strong>struts.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;!DOCTYPE struts PUBLIC
      "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
      "http://struts.apache.org/dtds/struts-2.3.dtd"&gt;
  &lt;struts&gt;
      &lt;constant name="struts.convention.result.path" value="/"&gt;&lt;/constant&gt;
  
      &lt;package name="user" namespace="/" extends="struts-default"&gt;
          &lt;interceptors&gt;
              &lt;interceptor name="authentication" class="com.ibm.eaylportal.interceptors.AuthenticationInterceptor"&gt;&lt;/interceptor&gt;
              &lt;interceptor name="noCache" class="com.ibm.eaylportal.interceptors.CacheInterceptor"&gt;&lt;/interceptor&gt;
  
              &lt;interceptor-stack name="authStack"&gt;
                  &lt;interceptor-ref name="authentication"&gt;&lt;/interceptor-ref&gt;
                  &lt;interceptor-ref name="defaultStack"&gt;&lt;/interceptor-ref&gt;
              &lt;/interceptor-stack&gt;
  
              &lt;interceptor-stack name="authStack"&gt;
                  &lt;interceptor-ref name="noCache"&gt;&lt;/interceptor-ref&gt;
                  &lt;interceptor-ref name="defaultStack"&gt;&lt;/interceptor-ref&gt;
              &lt;/interceptor-stack&gt;
          &lt;/interceptors&gt;
  
          &lt;default-interceptor-ref name="authStack"&gt;&lt;/default-interceptor-ref&gt;
  
          &lt;global-results&gt;
              &lt;result name="login" type="redirect"&gt;/login.html&lt;/result&gt;
          &lt;/global-results&gt;
  
          &lt;action name="home"&gt;
              &lt;interceptor-ref name="defaultStack"&gt;&lt;/interceptor-ref&gt;
              &lt;result&gt;/login.html&lt;/result&gt;
          &lt;/action&gt;
  
          &lt;action name="login" class="com.ibm.eaylportal.actions.LoginAction"&gt;
              &lt;interceptor-ref name="defaultStack"&gt;&lt;/interceptor-ref&gt;
              &lt;result name="success"&gt;/welcome.jsp&lt;/result&gt;
              &lt;result name="input"&gt;/login.html&lt;/result&gt;
          &lt;/action&gt;
  
          &lt;action name="logout" class="com.ibm.eaylportal.actions.LoginAction" method="logout"&gt;
              &lt;interceptor-ref name="noCache"&gt;&lt;/interceptor-ref&gt;
              &lt;result&gt;/login.html&lt;/result&gt;
          &lt;/action&gt;
  
          &lt;action name="welcome" class="com.ibm.eaylportal.actions.WelcomeAction"&gt;
              &lt;result name="success"&gt;/welcome.jsp&lt;/result&gt;
          &lt;/action&gt;
  
      &lt;/package&gt;
  
  &lt;/struts&gt;
  </code></pre>
  
  <p>this is just a part of my ActionClass  </p>
  
  <p><strong>LoginAction.java</strong>  </p>
  
  <pre><code>    public String logout(){
          sessionAttributes.remove("USER");
          return SUCCESS;
      }  
  </code></pre>
  
  <p><strong>CacheInterceptor.java</strong>  </p>
  
  <pre><code>public String intercept(ActionInvocation invocation) throws Exception {
          System.out.println("Interceptor: Cache");
          HttpServletResponse response = ServletActionContext.getResponse();
  
          response.setHeader("Cache-Control", "no-cache");
          response.setHeader("Pragma", "no-cache");
          response.setHeader("Expires", "-1");
          return invocation.invoke();
      }
  </code></pre>
  
  <p>when the program execution reaches in that sessionAttributes.remove part, it stops the execution because of the NullPointerException.  </p>