package s2.ex.action;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class SessionTestAction extends ActionSupport {
public String execute() {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.put("USER_NAME", "Test User");
return SUCCESS;
}
package s2.ex.action;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;
public class SessionTest1Action extends ActionSupport implements SessionAware {
private Map session;
public void setSession(Map session) {
this.session = session;
}
public String execute() {
this.session.put("USER_NAME", "Test User 1");
return SUCCESS;
}
}
<%@ page contentType="text/html; charset=UTF-8" %>
<%@page pageEncoding="utf-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Session Test</title>
</head>
<body>
<h1><s:property value="#session.USER_NAME"/></h1>
<h1></h1>
</body>