Java – ArrayList e session JSP
•
Java
There is something wrong with my procedure
I have a servlet; Save session properties in this Servlet
ArrayList<Integer> list = new ArrayList<Integer>; list.add(1); request.getsession().setAttribute("list",list);
Now the property is string instead of ArrayList In fact, when I try to do:
request.getsession().getAttribute(list)
Is a string, not an array
I want an array
thank you
Solution
When you get properties from a session, you must cast:
ArrayList<Integer> list = (ArrayList<Integer>)request.getsession().getAttribute("list");
And the properties in the session are stored in the map, which is why the key you use is string. You must use string to retrieve the value
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码