You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Gail Xiang <ga...@WheelHouse.com> on 2001/09/21 21:36:45 UTC

Download Content using Struts action class

Hi,
	I have a question about downloading files using Struts action class.
The <a href> link for the Download is:

	<a
href="downloadContent.do?action=download&mimetype=<%=strMimeType%>&dir=<%=st
rDir%>">Download</a>

	in which downloadContent.do is mapped to an action class.  It works
fine functionally.

	However, when the "File Download" dialogue box is prompted, and the
user selects "Save this file to disk", the default name given in the "File
name" box in the next dialogue screen is "downloadContent.do" instead of the
file name.

	I tried to add /<%=filename%> after the "downloadContent.do" and was
hoping the <%=filename%> would show up as the default file name.  This did
not work since server does not know how to interpret
downloadContent.do/<%=filename%>.

	One interesting observation is if directly uses a jsp page to handle
the action, such as:

	<a
href="download.jsp/<%=filename%>?action=download&mimetype=<%=strMimeType%>&d
ir=<%=strDir%>">Download</a>

	the <%=filename%> does show up as the default file name in the "save
as" screen.  However, in my case I have to use an action class not a jsp
because jsp does not work functionally although it could recognize the file
name on the other hand.

	Any hints would be appreciated!

Thanks.

-Gail

Re: Download Content using Struts action class

Posted by Ernest Jones <ej...@netopia.com>.
I'm working on a similar thing and adding this line seems to help:
response.setHeader("Content-Disposition","attachment; filename=\"" +
myFileName+ "\";");



----- Original Message -----
From: "Gail Xiang" <ga...@WheelHouse.com>
To: <st...@jakarta.apache.org>
Sent: Friday, September 21, 2001 1:36 PM
Subject: Download Content using Struts action class


> Hi,
> I have a question about downloading files using Struts action class.
> The <a href> link for the Download is:
>
> <a
>
href="downloadContent.do?action=download&mimetype=<%=strMimeType%>&dir=<%=st
> rDir%>">Download</a>
>
> in which downloadContent.do is mapped to an action class.  It works
> fine functionally.
>
> However, when the "File Download" dialogue box is prompted, and the
> user selects "Save this file to disk", the default name given in the "File
> name" box in the next dialogue screen is "downloadContent.do" instead of
the
> file name.
>
> I tried to add /<%=filename%> after the "downloadContent.do" and was
> hoping the <%=filename%> would show up as the default file name.  This did
> not work since server does not know how to interpret
> downloadContent.do/<%=filename%>.
>
> One interesting observation is if directly uses a jsp page to handle
> the action, such as:
>
> <a
>
href="download.jsp/<%=filename%>?action=download&mimetype=<%=strMimeType%>&d
> ir=<%=strDir%>">Download</a>
>
> the <%=filename%> does show up as the default file name in the "save
> as" screen.  However, in my case I have to use an action class not a jsp
> because jsp does not work functionally although it could recognize the
file
> name on the other hand.
>
> Any hints would be appreciated!
>
> Thanks.
>
> -Gail