Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Error 500: OutPutStream already obtained

Thread view: 
loffemoffe - 13 Feb 2006 12:32 GMT
I'm running IBM WebSphere and got a problem with filetransfer.
I've got a txt-file with some data in it, but when I open the file
after downloading it the following message gets added in the end of the
text Error 500: OutPutStream already obtained.

What's the problem? Can someone please help me?!

This is my filedownload.jsp:

<jsp:useBean class="com.peregrine.oaa.archway.User" scope="session"
id="user"></jsp:useBean>
<%
....
sAttachment = "attachment; filename=\""+ sFileNameAtt +"\"";
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", sAttachment);

InputStream is = null;
OutputStream out2 = null;
try
 {
 out2 = response.getOutputStream();
 is = new FileInputStream(request.getRealPath("files/" + sDirectory +
sFileName));
 int i;
 while ((i=is.read()) != -1)
   {
   out2.write(i);
   }
}

finally
 {
 if(out2 != null)
   {
   out2.flush();
   out2.close();
   }
if (is != null)
 {
 is.close();
 }
}

%>
SMC - 14 Feb 2006 01:17 GMT
> I'm running IBM WebSphere and got a problem with filetransfer. I've got
> a txt-file with some data in it, but when I open the file after
> downloading it the following message gets added in the end of the text
> Error 500: OutPutStream already obtained.
>
> What's the problem? Can someone please help me?!

The thing with JSP is that is translated into servlet code with all the
literal output (carriage returns, spaces and all) turned into
out.println() code.

Once anything has been committed to the "out" (response objects)
OutputStream, you won't be able to "get" it like you have below.

It can be a tricky exercise to get around this. I'll post a short example
at the bottom.

<snip>
> sAttachment = "attachment; filename=\""+ sFileNameAtt +"\"";
> response.setContentType("application/octet-stream");
[quoted text clipped - 5 lines]
>   {
>   out2 = response.getOutputStream();

This fails if the OutputStream has already been "gotten". Like I mentioned
above.

We had to do the following sort of munging to ensure no leading whitespace
for one of our pages. Here's an example of what we did merged with some of
your code:

<%@ page import="java.io.*"
%><%@ page import="java.util.*"
%><%@ page import="java.text.*"
%><%--
These comments (and silly formatting above) remove newlines so that no
leading whitespace is printed
--%><jsp:useBean class="com.peregrine.oaa.archway.User" scope="session"
id="user"/><%--

--%><%
// Code to read file and output here... sAttachment = "attachment;
filename=\""+ sFileNameAtt +"\"";
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", sAttachment);

InputStream is = null;
OutputStream out2 = null;
try
 {
 out2 = response.getOutputStream();
 is = new FileInputStream(request.getRealPath("files/" + sDirectory +
sFileName));
 int i;
 while ((i=is.read()) != -1)
   {
   out2.write(i);
   }
}catch (Exception e){}
...
%>

Hope that works for you.

Signature

Sean

(overheard discussing Apache webserver errors): Brendan: "Error 550?
What's that?" Fred: "Error 500 + GST?"



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.