Servlet to JSP problem

C

charlesmusco

I have an arraylist defined and populated in a servlet. What I want to
do is pass the arraylist to a JSP and display the values in the
arraylist.

Now to accomplish this what I did was to take the request object and
set an attribute on it. The attribute I added was the ArrayList. The
problem was when the JSP receives the request and does a getAttribute
on the request it is saying the ArrayList is null.

Any ideas on how I can pass this arrayList from a servlet to a JSP?
 
I

impaler

I have an arraylist defined and populated in a servlet. What I want to
do is pass the arraylist to a JSP and display the values in the
arraylist.
problem was when the JSP receives the request and does a getAttribute
on the request it is saying the ArrayList is null.

It tries to get a string from the request not the arraylist.
Any ideas on how I can pass this arrayList from a servlet to a JSP?

Put it on the session in the servlet and retrieve it from there in the
JSP or you will have to serialize it somehow before putting it on the
request. Bear in mind that GET has a maximum allowed length. POST
doesn't.

Regards
 
M

Manish Pandit

Now to accomplish this what I did was to take the request object and
set an attribute on it. The attribute I added was the ArrayList.

This is the correct approach. However, if you are using struts and the
action is set to redirect="true", the request will never make it to the
JSP and you'd have to use the session. Unless you are changing the
model in your servlet (i.e. processing a POST), there is no reason to
use redirect.
The
problem was when the JSP receives the request and does a getAttribute
on the request it is saying the ArrayList is null.

Make sure you are using the correct attribute name - it is case
sensitive.

-cheers,
Manish
 
S

Simon Brooke

in message <[email protected]>,
I have an arraylist defined and populated in a servlet. What I want to
do is pass the arraylist to a JSP and display the values in the
arraylist.

Now to accomplish this what I did was to take the request object and
set an attribute on it. The attribute I added was the ArrayList. The
problem was when the JSP receives the request and does a getAttribute
on the request it is saying the ArrayList is null.

Any ideas on how I can pass this arrayList from a servlet to a JSP?

Cache it on the Session.
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top