• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using RequestDispatcher Forward method giving NullPointer Exception

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

I have used the RequestDispatcher i jsp to forward the request to another jsp,but giving NullPointer Exception

here are those lines:

if(request.getParameter("fromXmlFeed")==null && dataObjects.get("toClintFeed")==null)
{
RequestDispatcher rd = request.getRequestDispatcher("/VBClientFeed.jsp?toQuickQuote=true");
rd.forward(request,response);
}

Waiting for Your Reply

Thank You
 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which line is the exception occuring - it might be that 'if' statement
 
sasi kala
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You

but the error has occured at rd.forward line

looking forward for your reply
 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
most likely your getRequestDispatcher() call returned null, meaning there is nothing at "/VBClientFeed.jsp?toQuickQuote=true". Remember, if you start the path with a slash, it becomes relative to your application root, not to the request, so VBClientFeed.jsp must be present in the application's root director (not inside WEB-INF or /jsps or such).
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/VBClientFeed.jsp?toQuickQuote=true

I don't think you can do this. The RequestDispatcher expects a resource name, and you have given it more than that. It expects to be able to find a resource for a name that does not exist, and I'm reasonably sure the toQuickQuote part won't be evaluated.

Have you tried it just like this?

If it works it will confirm my theory.
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, it's always worked for me:




This works on Tomcat 5.0.30 at least. Works with <jsp:include> and <jsp:forward> too. I think there was even a question on this in one of the Head First Servlets & JSP mock tests, but I'm not sure.

[edit] Found it! Page 219, question 12, - Which statements about RequestDispatcher are true?".

"[]C. Parameters specified in the query string used to create a RequestDispatcher are not forwarded by the forward() method."

"Option C is incorrect because such parameters are forwarded in this case."

-Yuriy
[ August 19, 2005: Message edited by: Yuriy Zilbergleyt ]
reply
    Bookmark Topic Watch Topic
  • New Topic