aspose file tools*
The moose likes Servlets and the fly likes Problem with RequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with RequestDispatcher" Watch "Problem with RequestDispatcher" New topic
Author

Problem with RequestDispatcher

Lokesh Malik
Greenhorn

Joined: Feb 01, 2005
Posts: 7
Hi to ALL
Friends i have some problem regarding RequestDispatcher

on the base of code i am forwarding my message to another jsp page from servlet
and i use code

req.setAttribute("message","No Record Found");
RequestDispatcher rd = req.getRequestDispatcher("../Error.jsp");
rd.forward(req,res);

but when i run servlet this give Java.lang.NullPointerException on line rd.forward(req,res);
ie show rd is null;

it happens only first time and when i refresh the page it gives me proper output.

Please tell me why is this giving NullPointerException at first time and how could i prevent it.


Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Try this.

RequestDispatcher rd = req.getRequestDispatcher("/Error.jsp");
rd.forward(req,res);
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem with RequestDispatcher