This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Accessing values from session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Accessing values from session" Watch "Accessing values from session" New topic
Author

Accessing values from session

Rajaprabhu Aravindasamy
Greenhorn

Joined: Dec 26, 2011
Posts: 25
Hello guys..!
I just need to get an array of values from action class to jsp page through session..
i set the array to session by using the following code..

Map session = ActionContext.getContext().getSession();
session.put("array",s); //where s is an array

I can access it in the action classes by using the following code,

Map session = ActionContext.getContext().getSession();
String s1[]=(String[])session.get("array");

But my problem is i need to access that array in JSP page..!
so please post me a reply for fixing my problem soon..!
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

Suggestion : use sessionAware interface to get the session object it's best practice.


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
Rajaprabhu Aravindasamy
Greenhorn

Joined: Dec 26, 2011
Posts: 25
Yeah its working but guys i need to access the whole array in the jsp page..!
something like..

<% String s[]=%><s:property value="#session.array[]"/><% ; %>

I know it is wrong, but i need a solution similar to this..!
please post it soon...!
prashant thakre
Greenhorn

Joined: Jun 29, 2011
Posts: 2
Use SessionAware interface in your action class set a list in session
---------------------------------------------
List<String> list = new ArrayList<String>();
list.add("pp");
list.add("pp1");
list.add("pp2");
getSession().put("accList", list);
---------------------------------------
Dipslay in this way in your jsp
-----------------------------------------
<s:iterator value="%{#session.accList}" >
<s:property />
</s:iterator>

-------------------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing values from session
 
Similar Threads
Getting "HttpSession" object
session in Strut2
Application Context hash map on text field tag
How to store values in session using struts 2 and then how to retrieve values in a jsp
Struts 2 Session question: Using session to see if user is logged in?