You cannot use both getServletOutputStream()
and getWriter()
in same response.
Coming to your problem. Avoid writing scriptlets in JSP. Whatever you are doing in JSP , implement it in Servlet.
You are calling response.getOutputStream();
in JSP which is illegal. You should use either ServletResponse.getOutputStream()
or ServletResponse.getWriter()
.
Since JSP's use ServletResponse.getWriter() by default. You should write to ServletResponse.getWriter() instead ServletResponse.getOutputStream()
This is what Java Doc says :
getOutputStream...
ServletOutputStream getOutputStream() throws IOException
Returns a ServletOutputStream suitable for writing binary data in the response.
The servlet container does not encode the binary data.
Calling flush() on the ServletOutputStream commits the response.
Either this method or getWriter() may be called to write the body, not both.
Returns: a ServletOutputStream for writing binary data
Throws: IllegalStateException - if the getWriter method has been called on this response