Passing transfer from servlet to JSP

Hi, I am really going to die or atleast become insane if this thing doesn't get sort out soon and I am not joking! I am facing a strange problem. I have written a servlet and I am sending some data from servlet to a JSP.

I am really going to die or atleast become insane if this thing doesn't get sort out soon and I am not joking!

well, dont. we shall try and help

Given that 1.the page is loading with the correct data 2. the final url is /OnlineStore/OnlineStore.jsp ,it looks like the request is getting forwarded correctly,

so tell us what's in line number 73 below shopping.onlinestore.client.OnlineStoreServlet.doGet(OnlineStoreServlet.java:73) ?

why do you think the null pointer exception occured at the code you have posted?

ram.

Abhishek Asthana

Ranch Hand

Posts: 146

posted 13 years ago

Thanks for consoling! Line 73 is: Frankly I don't have any idea why is rd null. And since data is being displayed correctly in JSP,this is intriguing why the JSP page doesn't show up on its own. Abhishek.

Hi, Perhaps God listened to me or some miracle happened, or it were your wishes!!! This is the code that is working:

Can you find any difference between this code and the original one? I can't and I am surprised, why it is working now! But whatever thanks a lot to all of you, you really helped me. Thanks once again. Abhishek

I am facing the same thing. And unfortunately my problem is still LIVE !!. Actually I ahve a JSP page with some input fields.I am posting the page and data is passed on to servlets.Along with these input data, I have one vector as well which I need to pass on to servlet, so I did

request.setAttribute("vecName",vecData);

But when I am recieveing the same vector in Servlet with :

Vector vecSerData = (Vector)request.getAttribute("vecName");

It is giving me "null". And I am getting NULL POINTER EXCEPTION.

The vector is not null in jSP. When I say System.out.println(vecData); it prints something. But when I say same thing in Servlet .. it prints null.

Can any one tell me WHY??

Thanks in advance..

Nilesh Srivastava

Ranch Hand

Posts: 70

posted 12 years ago

Hi All,

I am facing the same thing. And unfortunately my problem is still LIVE !!. Actually I ahve a JSP page with some input fields.I am posting the page and data is passed on to servlets.Along with these input data, I have one vector as well which I need to pass on to servlet, so I did

request.setAttribute("vecName",vecData);

But when I am recieveing the same vector in Servlet with :

Vector vecSerData = (Vector)request.getAttribute("vecName");

It is giving me "null". And I am getting NULL POINTER EXCEPTION.

The vector is not null in jSP. When I say System.out.println(vecData); it prints something. But when I say same thing in Servlet .. it prints null.

When you say "input fields" do you mean HTML form fields, '<inpu type=text...'?

If so, the reason why is that, once the data is written to the user's browser, that request is over and gone. When the user submits the form, a NEW request has begun and that new request isn't going to have the attributes of the last one.

If you need your vector to survive across requests, you will need to store it in session scope. [ March 23, 2005: Message edited by: Ben Souther ]