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
posted 14 years ago
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.
Yes you can use OutputStreams with JSP's. I just did it then using:
java.io.OutputStream o = response.getOutputStream();
javax.naming.InitialContext iniCtx = new javax.naming.InitialContext();
javax.sql.DataSource dataSource = (javax.sql.DataSource)iniCtx.lookup("java:jdbc/datasource");
java.sql.Connection con = dataSource.getConnection();
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.
I'm not sure if I approve of this interruption. But this tiny ad checks out: