Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error: OutputStream already obtained

331 views
Skip to first unread message

Vinay Aggarwal

unread,
Dec 17, 2000, 2:46:34 PM12/17/00
to
Hi Everybody,

I am facing a problem with WebSphere 3.022 on WinNT.
Here is a JSP I am running.

<%
byte[] BlobBytes = new byte[4001];
java.io.FileInputStream fin = new
java.io.FileInputStream("c:\\temp\\myfile.zip");
fin.read(BlobBytes);
fin.close();

response.setContentType("application/x-octet-stream");
response.setHeader("Content-disposition", " inline;
filename=myfile.zip");
response.setContentLength(BlobBytes.length);

ServletOutputStream os = response.getOutputStream();
os.write(BlobBytes);
os.flush();
os.close();
%>

(The file c:\temp\myfile.zip length is 4001 bytes.)


When I call this JSP in my web browser, it returns me the file
correctly but also appends this error at the end of the response.


<HTML>
<HEAD><TITLE>Error Report</TITLE></HEAD>
<BODY>
<H1>Error 500</H1>
<H4>An error has occured while processing
request:http://mysystem/ws/test.jsp</H4>
<B>Message:</B>Server caught unhandled exception from servlet [JSP 1.0
Processor]<BR>
<B>Target Servlet: </B>JSP 1.0 Processor<BR>
<B>StackTrace: </B>
<HR width="100%">
<B>Root Error-1</B>: OutputStream already obtained<BR>
java.lang.IllegalStateException: OutputStream already obtained
at java.lang.Throwable.<init>(Throwable.java:74)
at java.lang.Exception.<init>(Exception.java:38)
at java.lang.RuntimeException.<init>(RuntimeException.java:43)
.......................
.......................


Further investigation showed the code generated as follows.


public final void _jspx_init() throws JspException {
ObjectInputStream oin = null;
try {
FileInputStream fin = new
FileInputStream("C:\\WebSphere\\AppServer\\temp\\default_host\\mysystem\\C_0003a.WStest.dat");
oin = new ObjectInputStream(fin);
_jspx_html_data = (StringBuffer[]) oin.readObject();
} catch (Exception ex) {
throw new JspException("Unable to open data file");
} finally {
if (oin != null)
try { oin.close(); } catch (IOException ignore) { }
}
}

public void _jspService(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

boolean _jspx_cleared_due_to_forward = false;
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
String _value = null;
try {

if (_jspx_inited == false) {
_jspx_init();
_jspx_inited = true;
}
_jspxFactory = JspFactory.getDefaultFactory();
try
{
response.setContentType("text/html");
}
catch (IllegalStateException ws_jsp_ise)
{
}
pageContext = _jspxFactory.getPageContext(this, request,
response,
"", true, 8192, true);

application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();

byte[] BlobBytes = new byte[4001];
java.io.FileInputStream fin = new
java.io.FileInputStream("c:\\temp\\myfile.zip");
fin.read(BlobBytes);
fin.close();

response.setContentType("application/x-octet-stream");
response.setHeader("Content-disposition", " inline;
filename=myfile.zip");
response.setContentLength(BlobBytes.length);

ServletOutputStream os = response.getOutputStream();
os.write(BlobBytes);
os.flush();
os.close();
// end
out.print(new String(_jspx_html_data[0]));

} catch (Throwable t) {
if ((!_jspx_cleared_due_to_forward) && (out.getBufferSize()
!= 0))
out.clear();
throw new
com.sun.jsp.JspWithNoErrorPageException("test.jsp", t);
} finally {
if (!_jspx_cleared_due_to_forward)
out.flush();
_jspxFactory.releasePageContext(pageContext);
}
}


I believe the error is coming at the line where it tries to put some
junk binary data
in the request (this one -> out.print(new String(_jspx_html_data[0]))
)


HAS ANYBODY ANY IDEA WHY WEBSPHERE CREATES THIS KIND OF .DAT FILES AND
TRIES TO APPEND THEM
TO THE RESPONSE? HOW CAN I DISABLE THIS? IF I CANNOT DISABLE THIS, HOW
CAN I GET RID OF THE
PROBLEM?

thanks for your time
Vinay

Chris Koenig

unread,
Dec 18, 2000, 12:24:06 PM12/18/00
to
Vinay,

It appears that you are trying to create a "second" output stream for the
JSP. The JSP already has a PrintWriter named "out" that is available for
output to the client. I think that this is what is giving you the error you
are seeing.

I think there may also be an issue with you trying to use an OutputStream
instead of the PrintWriter. I think that JSPs are geared towards text only
output. I haven't seen anything to indicate that they can be used with
binary data. ( I am new to this game, so don't hold me to this! )

Looking at the functionality in your JSP code, I see no HTML code contained
within it. If you are trying to implement this, you might want to consider
doing this in a servlet instead of using JSP.

The line of code and the .data file that you are asking about:
out.print(new String(_jspx_html_data[0]))

These show how JSPs handle the HTML code. JSP code is actually compiled
into a servlet. HTML code and script that is found in the JSP is placed,
line by line, into the .dat file. The servlet that is created will embed
output statements
to the PrintWriter where HTML statements were found.

Core Servlets and JavaServer Pages by Marty Hall is a good book containing
information on both servlets and JSPs. Check it out if you can.

Chris

Vinay Aggarwal <vina...@yahoo.com> wrote in message
news:3A3D181A...@yahoo.com...

Vinay Aggarwal

unread,
Dec 18, 2000, 2:06:43 PM12/18/00
to

There is no "Second" output stream. The "out" is the
PrintWriter and it cannot be used with binary data.
JSPs can be used with binary data. The use of OutputStream
is also legal and it is in specifications. I know what I
am trying to do in the code but I do not know what
websphere is trying to do. My part of the code is working
fine, all I want is that websphere should not mess with my
output and should not try to write anything to response on
its own.

Anyway, thanks for your response
Vinay

Ken Hygh

unread,
Dec 18, 2000, 6:49:03 PM12/18/00
to
Vinay,
Do not get the OutputStream, simply write your blob to out.

Ken

Freeze

unread,
Dec 19, 2000, 11:02:27 AM12/19/00
to
I have nearly the same problem with iPlanet webserver (Netscape). in fact
the jsp in translated in a servlet and some code is append to yours. At the
end of this code you can see an out.flush(). In my case the jsp engine is
jasper and when I look in the sources, out.flush, calls out.flushBuffer()
which calls initOut() which finally calls response.getWriter(). In the J2EE
API we can see that is response.getWriter throws an IllegalStateException if
response.getOutputStream is called before...
With Netscape it sends some useless message in the admin console. I don't
know how to say the server that it don't have to flush the output.

Vinay Aggarwal a écrit dans le message <3A3E6043...@yahoo.com>...

Vinay Aggarwal

unread,
Dec 19, 2000, 1:06:15 PM12/19/00
to

Have u tried it? Did it work? I tried it but it didn't work
properly. The "out" is JspWriter and it is not made for binary
data. It has no method to write the bytes directly. I tried to
convert the blob to String and write it but that changes a few
bytes.

Any ideas how can I do this?
Thanks
Vinay

0 new messages