Solved

how to set the session object in struts2 very urgent

Posted on 2009-05-11
8
4,158 Views
Last Modified: 2013-11-24
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.

Thanks.
0
Comment
Question by:massmen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 8

Expert Comment

by:Haris V
ID: 24361438
0
 
LVL 1

Author Comment

by:massmen
ID: 24361460
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

thanks
0
 
LVL 1

Author Comment

by:massmen
ID: 24361608
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);
b.setName("one");
list.add(b);
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.

Thanks.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:Gibu George
ID: 24366341
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.
0
 
LVL 12

Expert Comment

by:Gibu George
ID: 24366352
0
 
LVL 1

Author Comment

by:massmen
ID: 24370862
thanks for your replay

but my question is i'm setting like this

Map m=new HashMap();
m.put("test",list);
setSession(m);

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.

Thanks.
0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 500 total points
ID: 24371109
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"

0
 
LVL 1

Author Closing Comment

by:massmen
ID: 31580413
Thanks very much.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mapBully challenge 6 179
web services creation SOAP vs REST 5 87
hibernate jars 4 61
Setup GlassFish 4 37
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question