This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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.
This is the code for Servlet:
When I call this servlet in browser I get this:
But when I call http://127.0.0.1/OnlineStore/OnlineStore.jsp in browser I get the right page, with the data the servlet is supposed to pass to it. What can be the reason? I even used :
so the code becomes :
but this too doesn't help. Please help me!!! Thanks. I will pray to God for your health and prosperity! Abhishek.
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
Joined: Sep 08, 2004
Posts: 146
posted
0
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.
Without seeing all of your code, it's hard to guess what the problem is. It is generally a good practice to return right after forwarding or redirecting. Neither halts the excecution of your servlet.
Also, don't try to forward AND redirect. Do one or the other.
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 :
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
Joined: Aug 29, 2003
Posts: 70
posted
0
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 :
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 ]