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
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...
Anyway, thanks for your response
Vinay
Ken
Vinay Aggarwal a écrit dans le message <3A3E6043...@yahoo.com>...
Any ideas how can I do this?
Thanks
Vinay