[JSP] Is it possible to put a List into a session and use on a different page?

S

Steven

Hi everyone,

I've got a simple list like :
----
List names = new ArrayList();

names.add("Bill");

names.add("Mark");

names.add("John");

----

And I would like to put this list into a session :

session.setAttribute( "listnames", names);



And then on a different page loop through the list. Is this possible?

Thanks for any help!
 
H

Hikikomori

Yes you can. Just use:
List myList = (List)session.getAttribute("listnames");

There are a number of ways to iterate the list. Depending on your
needs, you can write scriptlets in JSP or use tag libraries like
DisplayTag which formats the output nicely in a html table.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top