Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IllegalStateException occur with RequestDispatcher

 
Lokesh Malik
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do I get the error "IllegalStateException" when using the RequestDispatcher?
 
Priya Jothi
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can u send the sample code where u got this IllegalStateException?.May be on seeing the code i can say why & where this exception is raised.

Regards,
Priya.
 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After using the dispatcher you can't use out.print.

One of the possible explanations.

But code would be cute

J.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lokesh Malik:
Why do I get the error "IllegalStateException" when using the RequestDispatcher?


Read the docs. It would be definitely helpful.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is your answer

Shailesh
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither requestDispatcher.forward nor request.sendRedirect will stop the execution of your request on their own.

It is always a good idea to follow a call to either with a return statement.
Another approach is to structure the flow of your page with if statements so that the the call to forward or sendRedirect are always the last call in their respective branches.

 
Lokesh Malik
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
req.setAttribute("message","No Record Found");
RequestDispatcher rd = req.getRequestDispatcher("../Error.jsp");
rd.forward(req,res);

here when i start Tomcat-server then at first time it shows rd=null;
and display the nullpointerexception but when i refresh the page it chows me the message.
So why at first time rd become null;


Originally posted by Priya Jothi:
Hi,
Can u send the sample code where u got this IllegalStateException?.May be on seeing the code i can say why & where this exception is raised.

Regards,
Priya.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic