Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalStateException: getOutputStream() has already been called for this response

Tags:

java

jsp

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?

like image 986
ama Avatar asked Aug 22 '10 06:08

ama


People also ask

How do you solve getOutputStream () has already been called for this response?

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.

What is Java getOutputStream?

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.


1 Answers

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.

like image 126
Josef Hammer Avatar answered Nov 15 '22 16:11

Josef Hammer