I used getOutputStream() of response object in JSP.
Don't know if this will help--your code worked as is on my system (J2SDK 1.4.1, Tomcat 4.1.12, Linux)--but you're setting the content-type twice, and to two different values. In the
page directive, you specify
contentType="text/html; charset=8859_1", and then in the scriptlet, you do a
response.setContentType ("application/excel");. Try changing the one in the
page directive and deleting the one in the scriptlet. The servlet container may be calling
getOutputStream() when it sees the text MIME type so it can prepare the
out built-in variable.
Also, according to the J2EE design patterns, JSP's should only be used to produce text output. Any binary output (such as Excel files) should be produced with servlets--otherwise, the JSP becomes one big scriptlet (like this one).
try ... catchblock since you're not doing anything with it. Doing so will allow you to let the servlet container handle the errors (i.e. specify error pages in the web application deployment descriptor). Either that, or at least put the
flush()calls in it since they can throw
IOExceptions, too. :)
Finally, you should never close the servlet's output stream. Leave that up to the servlet container.