This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with RequestDispatcher  RSS feed

 
Lokesh Malik
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this.

RequestDispatcher rd = req.getRequestDispatcher("/Error.jsp");
rd.forward(req,res);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!