Servlet to JSP problem

Discussion in 'Java' started by charlesmusco@gmail.com, Oct 30, 2006.

  1. Guest

    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?
     
    , Oct 30, 2006
    #1
    1. Advertising

  2. impaler Guest

    On Oct 30, 5:13 pm, 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
     
    impaler, Oct 30, 2006
    #2
    1. Advertising

  3. 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
     
    Manish Pandit, Oct 30, 2006
    #3
  4. Simon Brooke Guest

    in message <>,
    ('') 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.

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

    ;; Madness takes its toll. Please have exact change.
     
    Simon Brooke, Nov 2, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mladen Adamovic
    Replies:
    4
    Views:
    445
    Mladen Adamovic
    Nov 23, 2003
  2. circuit_breaker
    Replies:
    2
    Views:
    2,045
    Jack Jia
    Apr 4, 2004
  3. Replies:
    0
    Views:
    4,441
  4. javadev
    Replies:
    5
    Views:
    12,998
    javadev
    Nov 16, 2006
  5. Replies:
    4
    Views:
    810
Loading...

Share This Page