tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Turner <tomcat-u...@johnturner.com>
Subject Re: [OFF TOPIC] ServletOutputstream Issue
Date Mon, 14 Apr 2003 19:09:29 GMT

Its the length of the content the browser is about to receive.

For example, this JSP code reads a GIF from disk and writes out the GIF to 
a client.  There are probably easier/more elegant ways to do it, but it 
works for me:

        String outputDir = 
serverConfig.getProperty("Inventory.Directory.Download");

        java.io.OutputStream o = response.getOutputStream();
        java.io.FileInputStream is = new java.io.FileInputStream(outputDir 
+ "/" + srcFile);
        java.io.File oFile = new java.io.File(outputDir + "/" + srcFile);

        response.setContentType("image/gif");
        response.setContentLength((int)oFile.length());

        byte[] buf = new byte[32 * 1024]; // 32k buffer

        int nRead = 0;
        while( (nRead=is.read(buf)) != -1 ) {
            o.write(buf, 0, nRead);
        }

        o.flush();
        o.close();// *important* to ensure no more jsp output

        // delete the file
        oFile.delete();

        return;

As you can see, the content length ends up being the size of the file.

John

On Mon, 14 Apr 2003 12:01:19 -0700 (PDT), Lior Shliechkorn 
<liorshliech@yahoo.com> wrote:

> What is the content length setting? I've tried basically everything but 
> I'm not able to get it to work. "Cox, Charlie" <ccox@cincom.com> 
> wrote:are you opening the URL in Excel or IE?
>
> if you are using IE try these:
> 1. does your URL for the servlet end in xls? IE handles PDF this way - 
> I'm
> not sure if xls would be the same. try adding ?x=xls to the end of your 
> URL
> and see if that works.
>
> 2. Are you setting the content-length? This may help.
>
> 3. Set the content-disposition :
> response.setHeader("Content-Disposition", "attachment;filename=abc.xls;") 
> ;
>
> hope that helps,
> Charlie
>
>> -----Original Message-----
>> From: Lior Shliechkorn [mailto:liorshliech@yahoo.com]
>> Sent: Monday, April 14, 2003 1:38 PM
>> To: Tomcat Users List
>> Subject: Re: [OFF TOPIC] ServletOutputstream Issue
>>
>>
>> Yes, I have the header in place, and the utility creates a workbook, and 
>> then I use the WorkBook.write( outputstream). But for some reason it's 
>> not recognizing the excel data, and it's trying to open it up as the 
>> servlet name in excel and saying that the file cannot be opened. But 
>> when I try to generate the file to disk it works fine.
>>
>> Erik Price wrote:
>>
>> Lior Shliechkorn wrote:
>> > Hi, I'm trying to use POI as a utility to generate a report in excel. 
>> The process to generate the report is as following (IIS5 & Tomcat 4.0.5) 
>> : 1. JSP page with a form2. Servlet to pass the req, res to another 
>> servlet (appropriate report)3. Servlet (1. for HTML view and 2. for 
>> Excel view) I have no problems except when I try to get the file to be 
>> opened or saved on the client side it's trying to open/save the servlet 
>> at step 2. It's not prompting to save an xls file or open one, and I'm 
>> getting an error of site unavailable and the download fails. Any help 
>> would be great with this, since I'm obviously missing something about 
>> the outputstream. Again, thanks for taking the time to review my 
>> question, Lior
>>
>> How does your servlet serve the Excel file? I am assuming that you are 
>> using POI to write directly to the ServletOutputStream, obtained with 
>> response.getOutputStream()? If I am not mistaken you may need to set the 
>> content-type of the outgoing response:
>>
>> response.setContentType("application/vnd.ms-excel");
>>
>>
>>
>> Erik
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>> ---------------------------------
>> Do you Yahoo!?
>> Yahoo! Tax Center - File online, calculators, forms, and more
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Tax Center - File online, calculators, forms, and more



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message