Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using RequestDispatcher, NullPointerException

 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using RequestDispatcher to forward data from servlet to JSP.


I am working in JBoss 3.2.1, When I run the servlet in browser I get this error:


What may be the problem? why is rd null? Please help.
Thanks,
Abhishek
 
Durga Prasanna Kar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to add the code as:
getServletContext().getRequestDispatcher(".....path.....");
Try this instead of request.something.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You have to add the code as:
getServletContext().getRequestDispatcher(".....path.....");
Try this instead of request.something.


You could obtain the RequestDispatcher object using the request object too.
Thus



is correct.

The problem in the original poster's code is that he has used Windows style path locator (../resource) to locate the jsp.

This is what the api has to say


The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root.


Thus to locate a jsp resource under the WEB-INF folder, use



If your jsp is registered as a servlet, you could also use the getNamedDispatcher() method of ServletContext



ram.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Durga Prasanna Kar:
You have to add the code as:
getServletContext().getRequestDispatcher(".....path.....");
Try this instead of request.something.


Better do this.

getServletContext().getRequestDispatcher("/<path>/<page>");

Note: it must begin with a "/".

As said earlier that we can get RequestDispatcher object using request object too. And if we go to the point.

[ March 02, 2005: Message edited by: Adeel Ansari ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic