• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Passing transfer from servlet to JSP

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you tell me what is in line 73 of OnlineStoreServlet.java??
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic