how to set the session object in struts2 very urgent

Hi Experts,

How to set the object to session struts2, if i set the object to session how to get the session object in jsp,
like i have list in list object i have beanObject, this list i have to set the session
once i set the list to session then how to get the list in jsp
could you give me some code.

Who is Participating?
mrjoltcolaConnect With a Mentor Commented:
1) The session object is created for you, you don't need to create a hashmap explicitly.
Use SessionAware interface in your action class to set the session variable in your action. It is assumed, in the class that implements SessionAware, that you are possibly "caching" the session so your methods can use it.

class MyAction implements SessionAware {      
      protected Map session;
      protected List list;

      public void setSession(Map session) { this.session = session; }

      public String method1() {
         // create list
         list = new ...
         // store it
         session.put("test", list);

      // method2.jsp can make use of list
      public String method2() {
          list = (List)session.get("test");


So the JSP code can use the "list" bean directly, or can refer to it with "session.list"

Haris VCommented:
massmenAuthor Commented:
Thanks your replay

my problem is how to set the my list into map and how i will get the list in jsp
could you give me some suggestion.
i got some links but i didn't get the flow where i can set the my list into the session

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

massmenAuthor Commented:
here is the my requirement,

i have list object like( Bean b=new Bean();//this is POJO class then i'm setting some values b.setId(1);
like i'm adding then i have to add this list into session i want to get the list whenever i need this ID and Name that is my requirement.

please send my some sample code this is very urgent.


Gibu GeorgeChief Technology OfficerCommented:
The class which puts the bean object into the list must implement the SessionAware interceptor as show in the link given by sirah. Then you can put your list into the Map named session. which will be available in the jsp which is the result of the action. Once you put it like that the object will be available throughout the session.
massmenAuthor Commented:
thanks for your replay

but my question is i'm setting like this

Map m=new HashMap();

then how to get the list in my jsp

that is my problem normal procedure is if u set the object to session
in jsp  Map l=(Map)session.getAttribute("test);
like this we wrote but in this scenario how to get the map
please tell me.

massmenAuthor Commented:
Thanks very much.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.