Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Servlet to JSP problem

Thread view: 
charlesmusco@gmail.com - 30 Oct 2006 18:13 GMT
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?
impaler - 30 Oct 2006 18:20 GMT
On Oct 30, 5:13 pm, charlesmu...@gmail.com wrote:
> 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
Manish Pandit - 30 Oct 2006 20:42 GMT
> 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
Simon Brooke - 02 Nov 2006 18:42 GMT
> 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
[quoted text clipped - 6 lines]
>
> Any ideas on how I can pass this arrayList from a servlet to a JSP?

Cache it on the Session.

Signature

simon@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/

       ;; Madness takes its toll. Please have exact change.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.