using forward and include together

Discussions

Web tier: servlets, JSP, Web frameworks: using forward and include together

  1. using forward and include together (1 messages)

    I have been trying to write a servlet that calls RequestDispatcher.forward after calling RequestDispatcher.include several times. When I try to run the servlet, I get an IllegalStateException at the call to forward. I know that I cannot call forward after committing output to the response buffer, but in this case, I am not, at any point,writing any output to the response. Neither in my main servlet, nor in the servlets I'm "including" do I write any kind of output to the response. In reviewing the servlet spec, I have not been able to find any indication that what I'm doing is not supposed to work. Has anyone else encountered this problem and found a way to overcome it? Any information or insight into this issue would be greatly appreciated.
  2. Well, I know the jsp:include tag requires a flush="true", whereby the content is flushed out to the output. I don't see anything in the RequestDispatcher.include( ) documentation (at a quick glance, anyway) that would indicate that the same is true, but if it is, that would cause the problem you seem to be having.

    You might want to find out either way if RequestDispatcher.include( ) has already flushed the content.

    Don't know if that helps; good luck.