getting an "IllegalStateException" when using the RequestDispatcher?
1)java.lang.IllegalStateException: Header already sent
2)java.lang.IllegalStateException: Cannot forward as Output Stream or Writer has already been obtained
Impact:
Slows down your servlet communication, and at times can make your application behave intermittently.
Solution:
Make sure you only have one RequestDispatcher.forward("url") coded in your servlet and make sure it is always placed at the very end.
Also there is an interesting tip adapted from:
http://www.jguru.com/faq/view.jsp?EID=501393
Which states that:
If you want your response-writers to be modular (one object to build the nav bar, one object to build the banner ad, one object to build the body, one object to build the page footer, etc.), you have two choices:
- use JavaBeans or Java method calls to build up the HTML in the response, or
- use RequestDispatcher.include() to bring in content from many little servlets from inside a master response-builder servlet.
No comments:
Post a Comment