I had a previous program which is working fine so I just copied the chunk of code and paste it on the new program which I am building. Basically my program will generate a report using JExcel API and then I will try to display it on the web so that user can Open/Save/Cancel it (the normal IE notification window). Furthermore, there is no error message on the tomcat log.
[ November 27, 2007: Message edited by: Maruli Lee ] [ November 27, 2007: Message edited by: Bear Bibeault ]
Of course it won't - JSP has automagically already gotten the output stream for character output - thats what JSP do. You are undoubtedly getting a java.io.IllegalStateException thrown at that point. See the JavaDocs.
Joined: Dec 09, 2004
I have modified my code to avoid using OutputStream since it will cause a lot of problem. Now my modified code looks like this:
After I ran through this code my JSP page will refresh and show me this screen:
In addition, Tomcat shows following message:
Nov 29, 2007 10:44:38 AM org.apache.jasper.runtime.PageContextImpl release WARNING: Internal error flushing the buffer in release()
As has been mentioned, JSPs are designed for output of text. Sending a binary file via JSP is tricky for a number of reasons.
I would recommend you read Bear's excellent article on this subject: The Secret Life of JavaServer Pages where he answers the question "Why does everyone tell me to use a servlet to send binary data to the browser? I wanna use a JSP!"
You've written it all in java code anyway - it SHOULD be a servlet.