The issue here is that your JSP is talking directly to the response OutputStream
. This technically isn't forbidden, but it's very much not a good idea.
Specifically, you call response.getOutputStream()
and write data to that. Later, when the JSP engine tries to flush the response, it fails because your code has already "claimed" the response. An application can either call getOutputStream
or getWriter
on any given response, it's not allowed to do both. JSP engines use getWriter
, and so you cannot call getOutputStream
.
You should be writing this code as a Servlet, not a JSP. JSPs are only really suitable for textual output as contained in the JSP. You can see that there's no actual text output in your JSP, it only contains java.