Sheldon,

I had a similar problem with Excel sheets, below is what finally worked.

*********************************************************************
//set response header, content type and content length
response.setHeader("Content-Disposition","inline;filename=Report_" +
        reportName.replaceAll(" ","").replaceAll("/","") + ".xls");
response.setContentType( "application/vnd.ms-excel" );
response.setContentLength( (int)stringBuffer.length() );
ServletOutputStream outputStream = response.getOutputStream();

//put to output stream
outputStream.write( stringBuffer.toString().getBytes() );
outputStream.close();
*********************************************************************

Claude.


----- Original Message ----- 
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, February 03, 2003 1:48 PM
Subject: RE: Streaming PDF file problem


> BTW, the code for streaming a servlet works perfectly as a stand alone
> servlet, but fails for IE in the struts framework.
> 
> Sheldon
> 
> >  -----Original Message-----
> > From: Chan, Sheldon  
> > Sent: Monday, February 03, 2003 9:36 AM
> > To: '[EMAIL PROTECTED]'
> > Subject: Streaming PDF file problem
> > 
> > Hi all,
> > 
> > I'm trying to stream a PDF from a Struts action by writing an array of
> > bytes to the OutputStream of HttpServletResponse.  It works great in
> > Mozilla, however it fails on IE.  When I attempt to execute the action, IE
> > brings up its "Save or Open" dialogue box with the request Url as the file
> > it's trying to save.  When I click on "Save", it gives me an error
> > dialogue of "Internet Explorer cannot download... ".  Any ideas?
> > 
> > Thanks in advance for any help.
> > 
> > Sheldon
> > 
> > 
> > Here's the psuedo-code.
> > 
> > OutputStream outputstream = null;
> > 
> > try {
> >     byte[] responseBytes = getBody().getBytes(ENCODING);
> > 
> >     response.setContentType("application/pdf");
> >     response.setContentLength(responseBytes.length);
> >     response.setHeader("Content-Disposition",  
> >                                   "attachment; filename=myfile.pdf");
> >     response.setHeader("Pragma", "no cache");
> >     response.setHeader("Cache-Control", "no-cache");
> > 
> >     outputStream = response.getOutputStream();
> >     
> >     outputStream.write(responseBytes, 0, responseBytes.length);
> > } catch (Exception e) {
> >    // do something
> > }  finally {
> >     outputStream.close();
> > }
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

Reply via email to