This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Look at the Java code that JSP pages generate - you will see that the JSP compiler puts in a call that sets "out" by getting a Writer from the response stream. Thats because JSP are designed to make it easy to send character streams. Any form of data that needs to be sent as a binary stream of bytes should be sent by a servlet, NOT a JSP. Bill
Joined: Nov 25, 2003
Thanks for the help william.
Is there any work around for it...
I have tried by closing the stream also.. still it gives the same exception.
If you have placed the process of getting the outputstream inside a try catch it will be easy to track completion depending on whether try block is successfully executed or not. A successful closing of stream can help you do what you require to do.
I was having the same issue. The postings here have been very helpful. My problem was in upgrading code from WebSphere 4.x to WebSphere 5.1. 4.x must be more forgiving than 5.1 because 5.1 was throwing the error, while 4.x never did.
To solve, I literally c/p the logic in the jsp and placed it in a new servlet. I placed a <jsp:forward page="/blahServlet" /> in the jsp, and it solved my issue w/o having to change all the pages that referenced the old/bad jsp.
I was having the same trouble.I rewrote the JSP to a Servlet and it worked like a charm.
I was getting a pdf as binary array and trying to display it in browser.First i was getting some weird characters in the display.
Then one fine morning, I was being shown the File Download message(You computer is trying to download a file.Some files maybe potentially harmful. File name, File type, Location . Open,Save,Cancel,More Info blah blah blah).
But curiously the file type was missing , file name was my whole URL ( .../record.jsp?ID=12345) and location was localhost(I am using WSAD and running the JSP on the test server). When I say Open on the File Download dialog,it started downloading and then errored out saying Could not download from location. On top of that I was getting the outputstream exception in my jsp.
Given below is the jsp code which gave me error.I was writing a scriplet.
If some one is having this same trouble, consider rewriting it to a Servlet.
java.sql.PreparedStatement stmt = con.prepareStatement("select top 1 photo from photos order by id desc");
java.sql.ResultSet rs = stmt.executeQuery();
Worked a charm! You can't have any spaces around otherwise it will use a JSPWriter.
Why use Servlets if you want to do a quick test? Servlets are a pain to setup.