Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with arrayList e session jsp

Tags:

java

jsp

servlets

I have a problem with my program.

I have a servlet; in this servlet save the session attribute

ArrayList<Integer> list = new ArrayList<Integer>;
list.add(1);
request.getsession().setAttribute("list",list);

Now the attribute is a String and not an ArrayList. In fact when i try to do:

request.getsession().getAttribute(list)

is a string and not an Array.

I want an Array.

Thanks

like image 255
zp26 Avatar asked Jul 27 '26 14:07

zp26


1 Answers

You have to cast when you get the attribute from the session like this:

 ArrayList<Integer> list = (ArrayList<Integer>)request.getsession().getAttribute("list");

And the attributes in the session are stored in a map, that is why the key you used is a String and you have to use a string to retrieve the value.

like image 130
Vincent Ramdhanie Avatar answered Jul 29 '26 06:07

Vincent Ramdhanie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!