• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Using RequestDispatcher, NullPointerException

 
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 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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to add the code as:
getServletContext().getRequestDispatcher(".....path.....");
Try this instead of request.something.
 
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


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.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic