session objects

M

morc

hi,

i was wondering how to put an array of ints into an Object.

session.setAttribute(String,Object);

how can i make it so that i can retrieve whats in the attribute into an
array of ints.

meaning something along the lines of

int[] = session.getAttribute(String);

i know that code won't work. if anyone knows what i mean and can help
me, please post.
thanks alot
-morc
 
D

Dave f

Use an ArrayList of the Object 'Integer'.

Integer i1 = new Integer(1);
Integer i3 = new Integer(3);

ArrayList list = new ArrayList();
list.add(i1);
list.add(i3);

session.setAttribute(String, list);

....then...

ArrayList listFromSession = (ArrayList)session.getAttribute(String);

Then listFromSession is the ArrayList of Integer objects.


Actually, I think arrays are Java Objects, so just put your int[] array
into the Session using setAttribute() and when you do getAttribute just
cast to an int array. I'm pretty sure that will work.
 
M

Manfred Rosenboom

Each array is also an object. So try the following code :

session.setAttribute("intArray", ia);

ia = (int[]) session.getAttribute("intArray");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top