Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

putting an array into a session?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Is this valid...

String [] sarray={"one","two"}
session.setAttribute("sarray",sarray);

I dont think it is, since this is a sequence
of objects and not a specific object..

but I cant say for certain thats true.


 
An array itself is an object. It doesn't matter that it contains other objects, it can be used any place where an
Code:
Object
is expected. Personally I would prefer to use a
Code:
Collection
that way if you want to switch the data structure to a
Code:
LinkedList
or some type of synchronized collection later than it is transparent to the clients.
 
ok, I can put it into the session.. but how do
I get it back out..?

I've tried...

String [] s=session.getAttribute("array");

and I've tried just getting the String representation
of it.. It just looks like hash code..
 
You have to cast it to the proper type, just like every
Code:
Object
you get from the HttpSession.
Code:
String[] s = (String[])session.getAttribute("array");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top