• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Array in session with JSP

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
thanks. that worked!
best regards
Parvathi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic