• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using RequestDispatcher Forward method giving NullPointer Exception

 
sasi kala
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • 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
 
Daniel Rhoades
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank You

but the error has occured at rd.forward line

looking forward for your reply
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • 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).
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!