After the response text is sent back to the client, there's nothing you can do with it. So basically, once you close the
PrintWriter instance, the response body is sent back to the client while you keep working with the
OutputStream associated with the response. When you close the stream, you can't do anything about the page's display content.
Personally I don't think it's wise to work on both the
PrintWriter and
OutputStream associated with a
HTTPServletResponse instance. More often than not, one gets to bump into an
IllegalStateException.
What
you should probably try to do is - when you send the control to this servlet, display the message on the screen at that point while you submit the request to this particular servlet. For eg - if you come here from a
JSP, in your JSP you can write a small JavaScript snippet which directs the user's browser to a static HTML using something like -
Thereafter, you can simply submit the JSP's form object. [your form object's action attribute should map to this servlet].