I have set a ArrayList in the Session object inside my Action class as shown
public class HelloWorld implements SessionAware
{
private Map session;
public HelloWorld() {
}
public String execute() {
List list = new ArrayList();
list.add("One");
list.add("One2");
list.add("One3");
list.add("One4");
list.add("One5");
list.add("One6");
list.add("One7");
session.put("MyList", list);
System.out.println("Hi inside ");
return "SUCCESS";
}
public void setSession(Map session) {
this.session = (Map) session;
}
public Map getSession() {
return (Map) session;
}
}
Please tell me how can i access this Session object “MyList” inside my JSP page
I have tried this way
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
<%
Map session = ContextAction.getContext().getSession();
%>
</body>
</html>
But i doesn’t know whether using ContextAction is preferable or not ??
Please tell me how can i access this Session “MyList” inside my JSP
I think you mean ActionContext, not ContextAction. Either way, that’s not the way to do it. The following examples show how to iterate over the list using both OGNL (standard Struts2 way) and JSTL (standard JSP way). You can use either approach.
Using OGNL
Using JSTL
Here’s some more information on the
<s:iterator/>tag: http://struts.apache.org/2.2.3/docs/iterator.html