This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array in session with JSP

 
parvathi Viswanathan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
thanks. that worked!
best regards
Parvathi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic