File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Array in session with JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Array in session with JSP" Watch "Array in session with JSP" New topic
Author

Array in session with JSP

parvathi Viswanathan
Greenhorn

Joined: Sep 25, 2000
Posts: 2
Hi
How can you store a String array in a session in JSP and access it from a different JSP page?
say, arr is a two dimensional array of Strings. I have put this in a session using session.setAttribute("session_array",arr).
In a different JSP file when I try to get this using the following.
String new_arry[][] = new String[rows][cols];
new_array = session.getAttribute("session_array");
I get an error saying new_array is a of type java.lang.String whereas the right hand side is an Object (java.lang.Object). Please help.
I have tried to declare this new_array as Object. But how do I use it as an array? What kind of casting / type conversion should I use?
Any help will be useful. Tight deadlines!!!
Parvathi. (vparvathi@i-three.com)
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
dear parvathi,
everything you have put in your session as the value parameter will automatically be casted to Object type as the prototype signature for putValue in HttpSession is
Httpsession.putValue(String name,Object value);
so whatever it is even it is an array,it will automatically be converted to Object type.
so if it is String[][],it will be converted to Object[][].
so you have to recast it as (String[][])HttpSession.getValue("GivenName");
i tried with respect to casting and succeded.
with regards
balraj
parvathi Viswanathan
Greenhorn

Joined: Sep 25, 2000
Posts: 2
hi
thanks. that worked!
best regards
Parvathi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array in session with JSP
 
Similar Threads
PropertyResourceBundle.getStringArray() doesn't quite work as expected...
passing string array to action parameter
exceptions and type casting confusion
tomcat session problem
How do you create an array of typesafe-collections?