Session Management in Struts 2

Tagged:  

Store session variable in Action Class:

Map session = ActionContext.getContext().getSession();
session.put("variableName", "variableValue");

Store session variable in View / JSP:

<s:set name="variableName" scope="session" value="'variableValue'"/>

Retrieve session variable in Action Class:

(String) ActionContext.getContext().getSession().get("variableName");
<s:property value="%{#session.variableName}"/>
<s:property value="#session['variableName']"/>

Destroy session variable:

Map session = ActionContext.getContext().getSession();
session.remove("userName"); 
ActionContext.getContext().getSession().clear();

Clean and simple explanation... loved it... Thank you
Keep it up...

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.