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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "IllegalStateException occur with RequestDispatcher" Watch "IllegalStateException occur with RequestDispatcher" New topic
Author

IllegalStateException occur with RequestDispatcher

Lokesh Malik
Greenhorn

Joined: Feb 01, 2005
Posts: 7
Why do I get the error "IllegalStateException" when using the RequestDispatcher?
Priya Jothi
Ranch Hand

Joined: Jul 13, 2004
Posts: 168
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

Joined: Jan 15, 2004
Posts: 149
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Aug 13, 2004
Posts: 1081

here is your answer

Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Lokesh Malik
Greenhorn

Joined: Feb 01, 2005
Posts: 7
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.
 
subject: IllegalStateException occur with RequestDispatcher
 
Similar Threads
Doubt on Attributes and Listeners
Sometimes RequestDispatcher is not forwarding URL
entity beans and UserTx methods
IlligalStateException
ServletOutputStream