You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Apache Wiki <wi...@apache.org> on 2005/05/27 03:27:55 UTC
[Struts Wiki] Update of "StrutsFileDownload" by NiallPemberton
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Struts Wiki" for change notification.
The following page has been changed by NiallPemberton:
http://wiki.apache.org/struts/StrutsFileDownload
------------------------------------------------------------------------------
== Content Disposition ==
=== Setting the Content Disposition ===
- DownloadAction doesn't cater for setting the content dispositon header. I guess at the moment the best way to do that would be override the execute() method and set it first, something like this...
+ DownloadAction doesn't cater for setting the content dispositon header. The easiest way is set it in the getStreamInfo() method, for example...
{{{
public class ExampleFileDownload extends DownloadAction{
-
protected StreamInfo getStreamInfo(ActionMapping mapping,
@@ -204, +203 @@
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
+
+ // File Name
+ String fileName = mapping.getParameter();
+
+ // Set the content disposition
+ response.setHeader("Content-disposition",
+ "attachment; filename=" + fileName);
// Download a "pdf" file - gets the file name from the
// Action Mapping's parameter
String contentType = "application/pdf";
- File file = new File(mapping.getParameter());
+ File file = new File(fileName);
return new FileStreamInfo(contentType, file);
- }
-
- public ActionForward execute(ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response)
- throws Exception {
-
- response.setHeader("Content-disposition",
- "attachment; filename=" + mapping.getParameter());
-
- return super.execute(mapping, form, request, response);
-
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org