aspose file tools*
The moose likes Servlets and the fly likes Using RequestDispatcher, NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Using RequestDispatcher, NullPointerException" Watch "Using RequestDispatcher, NullPointerException" New topic
Author

Using RequestDispatcher, NullPointerException

Abhishek Asthana
Ranch Hand

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

Joined: Feb 28, 2005
Posts: 5
You have to add the code as:
getServletContext().getRequestDispatcher(".....path.....");
Try this instead of request.something.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


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

Joined: Aug 15, 2004
Posts: 2874
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using RequestDispatcher, NullPointerException