They effect browser behaviour.

cache-control - used by browsers and proxies to determine wether to cache
the document or not, and if so, for how long.

content-length - not sure if struts would do this for you, but i know there
are issues with some browsers not liking binary data that it doesnt know the
length of.  Especially applies to pdfs.

Content-disposition - this is *very* usefull.  You can specify inline or
attachment.  Inline tells the browser to display the file in the browser.
(eg. the normal default behaviour for pdfs). Attachment tells the browser
that the file is to be downloaded rather than viewed, so the browser should
show the 'save file' dialog box.  Using filename=... with this allows you to
specify a filename for the attachment. So, if you have an action
download.do?id=6, it can say filename is tradereport-march-2004.pdf! Very
useful for reports, etc where you would otherwise have many files with the
same 'default' filename, ie report.pdf/whatever the browser decides.  Can be
used to reduce admin cockups!!!

Daniel.


> -----Original Message-----
> From: Erik Weber [mailto:[EMAIL PROTECTED]
> Sent: 25 August 2004 16:14
> To: Struts Users Mailing List
> Subject: Re: download binary content
>
>
> The difference between your implementation and mine is that I am not
> setting the Cache-Control, Content-Disposition and Content-Length
> headers. My download action seems to work fine in IE and Mozilla, but,
> could you enlighten me on what I may be sacrificing?
>
> Thanks,
> Erik
>
>
> Daniel Perry wrote:
>
> >Below is some code i wrote to do this. is some code i wrote:
> >
> >Note the doc object is specific to my app it has methods for
> returning the
> >content type, filename, and a File object pointing to the
> document on disk.
> >
> >I have used almost identicle code for outputting pdf data.  I
> think you can
> >use "attachment" rather than "inline" to make the browser save the file
> >rather than view it.
> >
> >Daniel.
> >
> >
> >// set response headers
> >response.setHeader("Cache-Control", "max-age=600");
> >response.setContentType(doc.getContentType());
> >
> >//Send content to Browser
> >StringBuffer cd = new StringBuffer();
> >cd.append("inline");
> >cd.append("; filename=");
> >cd.append(doc.getFilename());
> >response.setHeader("Content-disposition", cd.toString());
> >response.setContentLength((int) doc.getFile().length());
> >
> >// send data
> >ServletOutputStream sos;
> >sos = response.getOutputStream();
> >
> >InputStream is = new BufferedInputStream(new
> >FileInputStream(doc.getFile()));
> >
> >int bytesRead = 0;
> >byte[] buffer = new byte[8192];
> >while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
> >    sos.write(buffer, 0, bytesRead);
> >}
> >
> >sos.flush();
> >is.close();
> >
> >// return null so it just outputs data (no forward!)
> >return null;
> >
> >
> >
> >>-----Original Message-----
> >>From: Stefan Groschupf [mailto:[EMAIL PROTECTED]
> >>Sent: 25 August 2004 14:46
> >>To: Struts Users Mailing List
> >>Subject: download binary content
> >>
> >>
> >>Hi,
> >>can someone point me to a resource that describe how to realize a
> >>dowanload action?
> >>Do I can write to the response object with out forwarding?
> >>
> >>Thanks for any hints.
> >>Stefan
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >>
> >>
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to