I get the following exception when I'm trying to request loading images from server on client side:
241132533 [TP-Processor1] ERROR [/jspapps].[jsp] - Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response
Can any one explain this exception to me and also how to get over it?
Just comment out the call to getOutputStream() and everything will be Ok. To learn more about Servlet and JSP, read Head First Servlet and JSP, one of the best books from the last 10 years for learning JSP and Servlet.
The getOutputStream() method of Java Socket class returns an output stream for the given socket. If you close the returned OutputStream then it will close the linked socket.
I just stumbled upon this old question as I had the same issue. In the end it was quite easy to get rid of the exception: Just call out.clear()
before:
out.clear();
...
// later, in a different method
ServletOutputStream out = response.getOutputStream();
...
out.clear()
also helped me to get rid of all those empty lines from <%@page import=...
and the like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With