Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Servlet to JSP problem

Reply
Thread Tools

Servlet to JSP problem

 
 
charlesmusco@gmail.com
Guest
Posts: n/a
 
      10-30-2006

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?

 
Reply With Quote
 
 
 
 
impaler
Guest
Posts: n/a
 
      10-30-2006


On Oct 30, 5:13 pm, (E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
Manish Pandit
Guest
Posts: n/a
 
      10-30-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>
> 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

 
Reply With Quote
 
Simon Brooke
Guest
Posts: n/a
 
      11-02-2006
in message <(E-Mail Removed) .com>,
(E-Mail Removed) ('(E-Mail Removed)') 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.
>
> 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.

--
(E-Mail Removed) (Simon Brooke) http://www.jasmine.org.uk/~simon/

;; Madness takes its toll. Please have exact change.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening new child window - Running servlet (JSP and Servlet) agapitolw@yahoo.es Java 4 08-27-2007 12:57 PM
Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response javadev Java 5 11-16-2006 11:22 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM
jsp/servlet question : problem with repeating/retyping of code Mladen Adamovic Java 4 11-23-2003 11:33 AM



Advertisments