Struts2 Pass parameters with NO Session - struts2

I have a requirement where passing parameters from one action to another action with No sessions using: Here is my code, I am trying to use scope-interceptor.
here is my code I am not sure what am I doing wrong but I am not able to get the results.
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="HelloWorld" class="com.tutorials4u.helloworld.HelloWorld">
<result name="SUCCESS">/success.jsp</result>
</action>
<action name="FirstAction" class="com.tutorials4u.helloworld.FirstAction">
<interceptor-ref name="basicStack" />
<interceptor-ref name="scope">
<param name="session">myName</param>
<param name="key">person</param>
<param name="type">start</param>
</interceptor-ref>
<result name="SUCCESS">/success1.jsp</result>
</action>
<action name="SecondAction" class="com.tutorials4u.helloworld.SecondAction">
<interceptor-ref name="scope">
<param name="session">myName</param>
<param name="key">person</param>
</interceptor-ref>
<interceptor-ref name="basicStack" />
<result name="SUCCESS">/success2.jsp</result>
</action>
</package>
</struts>
*index.jsp*
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%#taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
<s:form action="HelloWorld" >
<s:textfield name="userName" label="User Name" />
<s:submit />
</s:form>
</body>
</html>
*Success.jsp*
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%#taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
<s:property value="person.myName"></s:property>
<s:form action="FirstAction" >
<s:submit value="Click for first Action"></s:submit>
</s:form>
</body>
</html>
*success1.jsp*
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%#taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
<s:property value="person.myName"></s:property>
<h1><s:property value="message" /></h1>I am in FIRST ACTION
<s:form action="SecondAction">
<s:submit value="click for 2nd action"></s:submit></s:form>
</body>
</html>
*success2.jsp*
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%#taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
<h1><s:property value="message" /></h1>2ND ACTION EXECUTED
<s:property value="person.myName"></s:property>
</body>
</html>
**ACTIONS**
package com.tutorials4u.helloworld;
import com.opensymphony.xwork2.ActionSupport;
/**
*
*
*/
public class HelloWorld extends ActionSupport{
private static final long serialVersionUID = 1L;
private String message;
private String userName;
public HelloWorld() {
}
public String execute() {
setMessage("Hello " + getUserName());
return "SUCCESS";
}
/**
* #return the message
*/
public String getMessage() {
return message;
}
/**
* #param message the message to set
*/
public void setMessage(String message) {
this.message = message;
}
/**
* #return the userName
*/
public String getUserName() {
return userName;
}
/**
* #param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
}
*FirstAction.java*
package com.tutorials4u.helloworld;
import com.opensymphony.xwork2.ActionSupport;
public class FirstAction extends ActionSupport {
/**
*
*/
private String myString;
private Person person;
private static final long serialVersionUID = 1L;
public FirstAction(){
}
public String execute() {
return "SUCCESS";
}
public String getMyString() {
return myString;
}
public void setMyString(String myString1) {
this.myString = myString1;
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
}
package com.tutorials4u.helloworld;
public class Person {
private String myName;
public String getMyName() {
return myName;
}
public void setMyName(String myName1) {
myName1 = "test string";
this.myName = myName1;
}
}
SecondAction.java
package com.tutorials4u.helloworld;
import com.opensymphony.xwork2.ActionSupport;
public class SecondAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private Person person;
public SecondAction(){
}
public String execute() {
return "SUCCESS";
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
}
---I would really appreciate if you can help me on where I was doing things wrong..
TIA

so we are instantiating session object in each and every other action
right?
Not at all, we are just retrieving it from the ServletActionContext.
How to put in session
ServletActionContext.getContext().getSession().put("softuser", someUserObject);
How to retrieve from session
ServletActionContext.getContext().getSession().get("softuser");

Related

Model object becomes null. Is there any change required for ModelDriven interface when upgrading from struts 2.3.35 to 2.5.26? [duplicate]

I am new to Struts 2 framework. I have made a program for understanding modelDriven interceptor. But I am unable to execute it. Following are the list of files and in the end there is a output (error).
index.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%-- <jsp:useBean id="ent" class="pack.Entity" scope="session" /> --%>
<s:form method="get" action="go">
<s:textfield name="t1" label="Name"></s:textfield>
<s:password name="p1" label="Password"></s:password>
<s:submit value="accept"></s:submit>
</s:form>
</body>
</html>
Entity.java:
package actions_pack;
public class Entity {
private String t1;
private String p1;
public String getP1() {
return p1;
}
public void setP1(String p1) {
this.p1 = p1;
}
public Entity() {
super();
// TODO Auto-generated constructor stub
}
public String getT1() {
return t1;
}
public void setT1(String t1) {
this.t1 = t1;
}
}
GoAction.java:
package actions_pack;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor;
import com.opensymphony.xwork2.util.ValueStack;
public class GoAction implements ModelDriven<Entity> {
private Entity en;
public Entity getEn() {
return en;
}
public void setEn(Entity en) {
this.en = en;
}
public String execute(){
System.out.println("inside action");
if(en.getT1().equalsIgnoreCase("nitin")){
return "success";
}
else{
return "failure";
}
}
#Override
public Entity getModel() {
System.out.println("inside model driven....");
en=new Entity();
return en;
}
}
struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="dd">
<result-types>
<result-type name="dispatcher"
class="org.apache.struts2.dispatcher.ServletDispatcherResult"
default="true" />
</result-types>
<interceptors>
<interceptor name="modelDriven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/>
<interceptor-stack name="myStack">
<interceptor-ref name="modelDriven"></interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="go" class="actions_pack.GoAction">
<interceptor-ref name="myStack"></interceptor-ref>
<result name="success" type="dispatcher" >/one/welcome.jsp</result>
<result name="failure" type="dispatcher">/one/error.jsp</result>
</action>
</package>
</struts>
welcome.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Welcome, <s:property value="t1"/>
</body>
</html>
web-page output(500 error):
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
actions_pack.GoAction.execute(GoAction.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.34 logs.
Apache Tomcat/7.0.34
In struts.xml file I don't want to use/extend struts-default package. Although, when I include params interceptor entry along with modelDriven interceptor in struts.xml, problem solves. What is the reason behind this. Can any one guide me?
You have a property in the action class that needs initialize prior to the action execution. You can do it in many ways.
The way you have chosen relies on modelDriven interceptor which is running before your action is executed. It invokes getModel() to push it on top of the valueStack. So, your entity property is being initialized. If you remove this interceptor you will get NullPointerException when the action is executed.
If your Entity is a simple POJO that you can instantiate yourself then simply do it inline instead of in getModel().
private Entity en = new Entity();
#Override
public Entity getModel() {
System.out.println("inside model driven....");
return en;
}
Next part is about params interceptor. It uses OGNL to populate a top object that is a model if you have used modelDriven interceptor prior params interceptor.
Living it along with your action allows to initialize some properties you reference in the execute().
For example t1 should be initialized.

Struts2 Global Result and global exception not working

I am trying to get the exception via struts2 to display the global results jsp but its not working and instead I am getting a java exception show in console. Also would like to add that If i use interceptor-ref exception individually to an action its working fine but globally not working as intended.
Here is my struts.xml, just addded a simple global results and exceptions.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts-devmode" value="true"></constant>
<package name="user" extends="struts-default">
<global-results>
<result name="myresult">globalresult.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="myresult" exception="java.lang.Exception"></exception-mapping>
</global-exception-mappings>
<action name="UserAction" class="actionclasses.UserAction"
method="execute">
<interceptor-ref name="timer"></interceptor-ref>
<interceptor-ref name="params"></interceptor-ref>
<result name="input">index.jsp</result>
<result name="success">success.jsp</result>
</action>
<action name="LoginAction">
<result type="redirect">login.jsp</result>
</action>
</package>
</struts>
My UserAction class from where exception is raised.
package actionclasses;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
String userName;
String passWord;
public String execute()
{
System.out.println(userName);
int a=10/0;
return "success";
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
My login.jsp, my login page
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib prefix='s' uri='/struts-tags' %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>User Login</title>
</head>
<body>
<h1>Login to Web page</h1>
<s:form action="UserAction" method="post">
<s:textfield name="userName" label="Enter UserName" />
<s:password name="passWord" label="Enter Password" />
<s:submit value="submit" />
</s:form>
</body>
</html>
Once you specify any interceptors you must specify all interceptors.

how to validate HashSet size greather than zero in Struts2 if tag?

I am using Struts2 and want to check the HashSet property size is greater than zero using Struts2 if tag.
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="bundle" extends="struts-default" namespace="/">
<action name="process"
class="sample.action.Process"
method="execute">
<interceptor-ref name="defaultStack" />
<result name="success">/jsp/result.jsp</result>
</action>
</package>
</struts>
POJO
package sample.pojo;
public class Customer{
private Integer id;
String name;
int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
Action Class
package sample.action;
import java.util.HashSet;
import java.util.Set;
import sample.pojo.Customer;
import com.opensymphony.xwork2.ActionSupport;
public class Process extends ActionSupport
{
private Set<Customer> result = new HashSet<Customer>();
public String execute()
{
Customer cust1 = new Customer();
cust1.setId(1);
cust1.setAge(59);
cust1.setName("Subramanian");
result.add(cust1);
return SUCCESS;
}
public Set<Customer> getResult() {
return result;
}
public void setResult(Set<Customer> result) {
this.result = result;
}
}
VIEW
<!DOCTYPE html>
<html>
<head>
<%# taglib prefix="s" uri="/struts-tags"%>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=8;" />
<title>Welcome Page</title>
</head>
<body>
<s:if test="*<syntax>*">
java.util.HashSet size is <s:property value="result.size"/>
</s:if>
<s:else>
java.util.HashSet size is empty!
</s:else>
</body>
</html>
Please help with the Struts2 if tag syntax to be used in the View. Thank you!
Below code snippet worked for me
<s:if test="%{mySet.size()>0}">

Struts2 validation is not even working

I also configured all the setting for Struts2 basic validation, but nothing is working for me.
My login.jsp file
<%#taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Login Page</title>
<s:head />
</head>
<body>
<s:actionerror/>
<s:form action="Login" method="post">
<s:textfield name="userName" label="User Name" />
<s:password name="password" label="Password" />
<s:submit value="Login" />
<s:fielderror></s:fielderror>
</s:form>
</body>
</html>
My loginAction class is,
package com.test;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String userName;
private String password;
public LoginAction() {
}
public String execute() {
return "SUCCESS";
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
my struts2.xml file is,
<package name="default" namespace="/" extends="struts-default">
<action name="Login" class="com.test.LoginAction" method="execute">
<result name="SUCCESS">login.jsp</result>
<result name="input">login.jsp</result>
</action>
</package>
</struts>
And I place my LoginAction-validation.xml file in the same package where the Action class is placed.
Please lookout my code and help me to resolve the validation issue.
You are returning same login.jsp page in your execute method in action class.
So this results in displaying login page with empty field every time you hit enter.
Try creating an additional jsp to which you are redirected to based on String returned from action class.
other than that i dont see any problem.

Problems with Login application in struts2

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.
Login.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%#taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
</head>
<body>
<s:form action="login">
<s:textfield name="myname"></s:textfield>
<s:submit value="submit"></s:submit>
</s:form>
</body>
</html>
Struts.xml
<interceptors>
<interceptor name="clear-cache" class="ActionClasses.ClearCacheInterceptor" />
</interceptors>
<action name="login" class="ActionClasses.LoginAction" >
<interceptor-ref name="clear-cache" />
<result name="success">Welcome.jsp</result>
<result name="error">Login.jsp</result>
</action>
<action name="logout" class="ActionClasses.Logout">
<interceptor-ref name="clear-cache" />
<result name="success">Logout.jsp</result>
</action>
LoginAction.java
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<String , Object> 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<String, Object> arg0) {
// TODO Auto-generated method stub
s=arg0;
}
}
ClearcacheInterceptor.java
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;
}
}
Logout.java
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<String,Object> s=ActionContext.getContext().getSession();
s.remove("login");
ActionContext.getContext().getSession().clear();
return "success";
}
}
Welcome.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# page contentType="text/html; charset=UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<s:include value="CheckLogin.jsp"></s:include>
<%# taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
</head>
<body>
<font color="white"></font>
Welcome<s:property value="#session['login']"/>
<s:a href="logout">Logout</s:a>
</body>
</html>
Logout.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
log out successful !!
</body>
</html>
CheckLogin.jsp
<%# taglib prefix="s" uri="/struts-tags" %>
<%# page language="java" contentType="text/html" import="java.util.*"%>
<html>
<head>
<title>Check validate!</title>
</head>
<body>
This is session validation page!
<s:if test="#session.login != 'Jagan'">
<jsp:forward page="Login.jsp" />
</s:if>
</body>
</html>
Well that's a very common issue and this is with respect to your browser cache issue rather than struts2 or any other framework at all.
we have face same problem since when you hit the back button of browser the request is not being send to the server rather it is being serves from the browser cache.you will only notice things when you try to do some work and it will come up with error that you are no longer being logged in.
though you can use certain header like no-cache etc but they are being obeyed by the browser is not certain.
only workaround to this problem as per my understanding is to use https (secure browsing) for your work and than use the header (no-cache. cache-expiry etc) since when you browse application under secure mode these header will be followed by the server and browser.
i hope this will try to give you an idea, just to check redirect to https protocol when your logout and it will solve your problem

Resources