title: Problems with Login application in struts2
body: <p>I am trying to write small login application in struts 2.Session is b eing created successfully.In welcome.jsp "logout" option is given.On logout control will be  redirected to Logout.jsp.
                     My problem is after logout session variables are destroyed but pages are storing in browser cache.If click back button of browser i am able to see welcome.jsp.
  For clearing cache "ClearCacheInterceptor" is used.I don't understand where i am making mistake.
                     Instead of clearing browser every time is there any to overcome this prooblem ? Is my approach correct ? Please suggest me.</p>
  
  <p>Login.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;%@taglib  uri="/struts-tags"  prefix="s"  %&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=UTF-8"&gt;
  &lt;title&gt;Login&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;s:form action="login"&gt;
          &lt;s:textfield name="myname"&gt;&lt;/s:textfield&gt;
          &lt;s:submit value="submit"&gt;&lt;/s:submit&gt;
      &lt;/s:form&gt;
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>Struts.xml</p>
  
  <pre><code>&lt;interceptors&gt;
              &lt;interceptor name="clear-cache"  class="ActionClasses.ClearCacheInterceptor" /&gt;
           &lt;/interceptors&gt;
  
          &lt;action name="login" class="ActionClasses.LoginAction" &gt;
             &lt;interceptor-ref name="clear-cache" /&gt; 
             &lt;result name="success"&gt;Welcome.jsp&lt;/result&gt;
             &lt;result name="error"&gt;Login.jsp&lt;/result&gt;
          &lt;/action&gt;  
  
          &lt;action name="logout" class="ActionClasses.Logout"&gt;
            &lt;interceptor-ref name="clear-cache" /&gt; 
            &lt;result name="success"&gt;Logout.jsp&lt;/result&gt;
          &lt;/action&gt;  
  </code></pre>
  
  <p>LoginAction.java</p>
  
  <pre><code>package ActionClasses;
  import java.util.Map;
  
  import org.apache.struts2.interceptor.SessionAware;
  
  import com.opensymphony.xwork2.ActionContext;
  import com.opensymphony.xwork2.ActionSupport;
  import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
  import com.opensymphony.xwork2.validator.annotations.ValidatorType;
  import java.util.Map;
  
  import javax.servlet.http.HttpServletResponse;
  
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.struts2.ServletActionContext;
  
  import com.opensymphony.xwork2.ActionContext;
  import com.opensymphony.xwork2.ActionInvocation;
  import com.opensymphony.xwork2.ActionSupport;
  import com.opensymphony.xwork2.interceptor.Interceptor;
  
  public class LoginAction extends ActionSupport implements SessionAware
  {
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
      private String myname;
      private Map&lt;String , Object&gt; s;
  
      public String execute()throws Exception
      {
  
              s=ActionContext.getContext().getSession();
              s.put("login", myname);
  
           return "success";
  
     }
  
  
      public void setMyname(String s)
      {
  
          myname=s;
  
      }
  
      public String getMyname()
      {
          return myname;
      }
  
  
      @Override
      public void setSession(Map&lt;String, Object&gt; arg0) {
          // TODO Auto-generated method stub
          s=arg0;
      }
    }
  </code></pre>
  
  <p>ClearcacheInterceptor.java</p>
  
  <pre><code>package ActionClasses;
  
  
  
  
  
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.struts2.StrutsStatics;
  
  
  
  import com.opensymphony.xwork2.ActionContext;
  
  import com.opensymphony.xwork2.ActionInvocation;
  
  import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
  
  
  
  public class ClearCacheInterceptor  extends AbstractInterceptor{
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
  
      @Override
  
      public String intercept(ActionInvocation invocation) throws Exception {
  
          ActionContext context=(ActionContext)invocation.getInvocationContext();
  
          HttpServletResponse response=(HttpServletResponse)context.get(StrutsStatics.HTTP_RESPONSE);
  
          response.setHeader("Cache-Control", "no-cache");
  
          response.setHeader("Pragma", "no-cache");
  
          response.setDateHeader("Expires", 0);
  
          String result=invocation.invoke();
  
          System.out.println("check result="+result);
  
          return result;
  
      }
  
  }
  </code></pre>
  
  <p>Logout.java</p>
  
  <pre><code>package ActionClasses;
  
  import java.util.Map;
  
  import com.opensymphony.xwork2.ActionContext;
  import com.opensymphony.xwork2.ActionSupport;
  
  
  public class Logout extends ActionSupport  {
  
  
  
      public String execute(){
  
          Map&lt;String,Object&gt; s=ActionContext.getContext().getSession();
  
  
  
          s.remove("login");
  
  
  
          ActionContext.getContext().getSession().clear();
  
  
  
          return "success";
      }
  
  
  
  }
  </code></pre>
  
  <p>Welcome.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;%@ page contentType="text/html; charset=UTF-8"%&gt;
  &lt;%@ taglib prefix="s" uri="/struts-tags"%&gt;
  &lt;s:include value="CheckLogin.jsp"&gt;&lt;/s:include&gt;
  &lt;%@ taglib prefix="s" uri="/struts-tags"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;font color="white"&gt;&lt;/font&gt;
  Welcome&lt;s:property value="#session['login']"/&gt;
  &lt;s:a href="logout"&gt;Logout&lt;/s:a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Logout.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;%@ taglib prefix="s" uri="/struts-tags"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  log out successful !!
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>CheckLogin.jsp</p>
  
  <pre><code>&lt;%@ taglib prefix="s" uri="/struts-tags" %&gt;
  &lt;%@ page language="java" contentType="text/html" import="java.util.*"%&gt;
  &lt;html&gt;
    &lt;head&gt;
    &lt;title&gt;Check validate!&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
    This is session validation page!
  
    &lt;s:if test="#session.login != 'Jagan'"&gt;
    &lt;jsp:forward page="Login.jsp" /&gt;  
    &lt;/s:if&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>