This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Passing transfer from servlet to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing transfer from servlet to JSP" Watch "Passing transfer from servlet to JSP" New topic
Author

Passing transfer from servlet to JSP

Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
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.
Hari Gangadharan
Ranch Hand

Joined: Mar 08, 2001
Posts: 73
Can you tell me what is in line 73 of OnlineStoreServlet.java??


<B>Hari Gangadharan</B><BR>Unix is user friendly..<BR>but it chooses to whom it is friendly with!
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


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
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.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
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
Nilesh Srivastava
Ranch Hand

Joined: Aug 29, 2003
Posts: 70
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.

Can any one tell me WHY??

Thanks in advance..
Nilesh Srivastava
Ranch Hand

Joined: Aug 29, 2003
Posts: 70
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.

Can any one tell me WHY??

Thanks in advance..
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing transfer from servlet to JSP
 
Similar Threads
Using RequestDispatcher, NullPointerException
I am not getting any error message
RequestDispatcher Problem
RequestDispatcher Problem
Problem in running session beans