Thanks for that.
I actually just needed to implement the ServletResponseAware interface to 
access the servlet response properly.

Trying to set those in the JSP (through a scriplet) didn't work, but indeed 
doing it in the action is fine.


-----Original Message-----
From: Brad A Cupit [mailto:[EMAIL PROTECTED]
Sent: 08 April 2008 14:25
To: Struts Users Mailing List
Subject: RE: Downloading file rendered in JSP

To set the download file name, in addition to the "text/csv" mime type
(which you already have set), write the following java code in your
Action or (if necessary) as Java in your JSP:

response.setHeader("Content-disposition", "attachment; filename=" +
CSV_FILE_NAME);

where CSV_FILE_NAME is the name you want the user to see for the csv
file.

Since this is a dynamically generated file, if you're using https and
need to work in IE you may also want to set the following:

response.setHeader("Cache-Control", "max-age=0");
response.setHeader("Pragma", "public");

see the following two links for more details:
http://eirikhoem.wordpress.com/2007/06/15/generated-pdfs-over-https-with
-internet-explorer/

http://forum.java.sun.com/thread.jspa?threadID=233446&forumID=45

Brad Cupit
Louisiana State University - UIS

-----Original Message-----
From: David Loup [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 08, 2008 7:42 AM
To: user@struts.apache.org
Subject: Downloading file rendered in JSP

Hi,

I'm trying to make one of my pages downloadable as a CSV file.

Currently my XML is configured like this:
<action name="downloadCSV" class="test.struts.ListItems"
method="downloadCSV">
                <interceptor-ref name="standardStack"/>
                <result name="success">/pages/download.jsp</result>
</action>

And /pages/download.jsp renders the list as a CSV.

I have changed the content type in the CSV:
<%@ page contentType="text/csv" %>

But I'd like to force the contentDisposition so that I can control the
filename.

I know it's easy to do that using StreamResult, but that doesn't look
like the right solution for me, since I don't want to access a file on
the file system and return it, but rather offer a page rendered by that
JSP as downloadable.

Is there any way to do this, or a way to use StreamResult and configure
it so that it can work with a page rendered by a JSP?

Thanks
D.

________________________________________________________________________

CONFIDENTIALITY - This email and any files transmitted with it, are
confidential, may be legally privileged and are intended solely for the
use of the individual or entity to whom they are addressed. If this has
come to you in error, you must not copy, distribute, disclose or use any
of the information it contains. Please notify the sender immediately and
delete them from your system.

SECURITY - Please be aware that communication by email, by its very
nature, is not 100% secure and by communicating with Perform Group by
email you consent to us monitoring and reading any such correspondence.

VIRUSES - Although this email message has been scanned for the presence
of computer viruses, the sender accepts no liability for any damage
sustained as a result of a computer virus and it is the recipient's
responsibility to ensure that email is virus free.

AUTHORITY - Any views or opinions expressed in this email are solely
those of the sender and do not necessarily represent those of Perform
Group.

COPYRIGHT - Copyright of this email and any attachments belongs to
Perform Group, Companies House Registration number 6324278.

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


________________________________________________________________________

CONFIDENTIALITY - This email and any files transmitted with it, are 
confidential, may be legally privileged and are intended solely for the use of 
the individual or entity to whom they are addressed. If this has come to you in 
error, you must not copy, distribute, disclose or use any of the information it 
contains. Please notify the sender immediately and delete them from your system.

SECURITY - Please be aware that communication by email, by its very nature, is 
not 100% secure and by communicating with Perform Group by email you consent to 
us monitoring and reading any such correspondence.

VIRUSES - Although this email message has been scanned for the presence of 
computer viruses, the sender accepts no liability for any damage sustained as a 
result of a computer virus and it is the recipient’s responsibility to ensure 
that email is virus free.

AUTHORITY - Any views or opinions expressed in this email are solely those of 
the sender and do not necessarily represent those of Perform Group.

COPYRIGHT - Copyright of this email and any attachments belongs to Perform 
Group, Companies House Registration number 6324278.

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

Reply via email to