I would like to build a dynamic HTML page including a JSP page whith the RequestDispatcher(...).include(...). But the OutputStream cannot be opened from both my servlet and the JSP. Is there any workaround ?

Ryan Breidenbach

My solution to this problem would be this - don't have your servlet open the OutputStream at all. Leave this to this JSP. JSPs were created to write the output of the user's request. It is much better technology for writing HTML and XML than servlets are. So, unless you have some specific reason for writing output in your servlet, I would leave this work to your JSPS, and let your servlet(s) control your page/application flow.

This design of having servlets control page flow and JSPs handling display logic is commonly known as the Model 2 Architecture. For more on this, see Govind Seshadri's article.

One note on this - one scenario in which you would want your servlet to write the response is if the response is binary - some sort of file format. In this case, you can awlays include a link to a servlet in your HTML ala:

<img SRC="/myservet?imageName=smileyFace">