You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by quinquin2209 <qu...@yahoo.com.hk> on 2008/05/28 13:22:11 UTC
How to promt SaveAs dialog when a file is to be downloaded?
Hi,
I am not sure if this is a javascript question or structs question. But I
hope you may help.
I have a page which will list out attachments of a message. When user click
on the attachment, it is expected that a SaveAs dialog should be prompted
such that user can download the file.
In struts.xml, I define something like this:
<action name="download" method="downloadAttachment"
class="attachmentAction">
<result name="success" type="stream">
inputStream
filename="${downloadAttachmentFileName}"
4096
</result>
<result name="input" type="redirect-action">
list
/message
${docId}
</result>
</action>
And in the html, I write like this
<s:url id="downloadUrl" action="../attachment/download.action">
<s:param name="downloadAttachmentFileName"
value="attachments[#status.index].name"/>
</s:url>
<s:a href="%{downloadUrl}"><s:property
value="attachments[#status.index].name" /></s:a>
So now when the file name is clicked, it will automatically show the file
content in a new page.
Can anyone suggest how I can open a SaveAs dialog when the file is clicked?
I look from the web knowing that document.execCommand("SaveAs"); is the
javascript to open the SaveAs dialog. But I don't know how can I combine
this in my page. Any suggestion?
Queenie
--
View this message in context: http://www.nabble.com/How-to-promt-SaveAs-dialog-when-a-file-is-to-be-downloaded--tp17510502p17510502.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to promt SaveAs dialog when a file is to be downloaded?
Posted by quinquin2209 <qu...@yahoo.com.hk>.
Hi,
Thanks for your kindly help. It works fine now.
Queenie
Gabriel Belingueres-2 wrote:
>
> You have to set the Content-Disposition in the HTTP header. See
> http://www.ietf.org/rfc/rfc2183.txt for the details, but setting as
> "attachment" will ask for the save dialog. Set the "filename" too if
> you want to pre-set the saved filename.
> See http://www.javaworld.com/javaworld/javatips/jw-javatip94.html for
> an example.
>
> 2008/5/28, quinquin2209 <qu...@yahoo.com.hk>:
>>
>> Hi,
>>
>> I am not sure if this is a javascript question or structs question. But I
>> hope you may help.
>>
>> I have a page which will list out attachments of a message. When user
>> click
>> on the attachment, it is expected that a SaveAs dialog should be prompted
>> such that user can download the file.
>>
>> In struts.xml, I define something like this:
>>
>> <action name="download" method="downloadAttachment"
>> class="attachmentAction">
>> <result name="success" type="stream">
>> inputStream
>> filename="${downloadAttachmentFileName}"
>> 4096
>> </result>
>> <result name="input" type="redirect-action">
>> list
>> /message
>> ${docId}
>> </result>
>> </action>
>>
>> And in the html, I write like this
>>
>> <s:url id="downloadUrl" action="../attachment/download.action">
>> <s:param name="downloadAttachmentFileName"
>> value="attachments[#status.index].name"/>
>> </s:url>
>> <s:a href="%{downloadUrl}"><s:property
>> value="attachments[#status.index].name" /></s:a>
>>
>> So now when the file name is clicked, it will automatically show the file
>> content in a new page.
>>
>> Can anyone suggest how I can open a SaveAs dialog when the file is
>> clicked?
>> I look from the web knowing that document.execCommand("SaveAs"); is the
>> javascript to open the SaveAs dialog. But I don't know how can I combine
>> this in my page. Any suggestion?
>>
>> Queenie
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-promt-SaveAs-dialog-when-a-file-is-to-be-downloaded--tp17510502p17510502.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/How-to-promt-SaveAs-dialog-when-a-file-is-to-be-downloaded--tp17510502p17526561.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to promt SaveAs dialog when a file is to be downloaded?
Posted by Gabriel Belingueres <be...@gmail.com>.
You have to set the Content-Disposition in the HTTP header. See
http://www.ietf.org/rfc/rfc2183.txt for the details, but setting as
"attachment" will ask for the save dialog. Set the "filename" too if
you want to pre-set the saved filename.
See http://www.javaworld.com/javaworld/javatips/jw-javatip94.html for
an example.
2008/5/28, quinquin2209 <qu...@yahoo.com.hk>:
>
> Hi,
>
> I am not sure if this is a javascript question or structs question. But I
> hope you may help.
>
> I have a page which will list out attachments of a message. When user click
> on the attachment, it is expected that a SaveAs dialog should be prompted
> such that user can download the file.
>
> In struts.xml, I define something like this:
>
> <action name="download" method="downloadAttachment"
> class="attachmentAction">
> <result name="success" type="stream">
> inputStream
> filename="${downloadAttachmentFileName}"
> 4096
> </result>
> <result name="input" type="redirect-action">
> list
> /message
> ${docId}
> </result>
> </action>
>
> And in the html, I write like this
>
> <s:url id="downloadUrl" action="../attachment/download.action">
> <s:param name="downloadAttachmentFileName"
> value="attachments[#status.index].name"/>
> </s:url>
> <s:a href="%{downloadUrl}"><s:property
> value="attachments[#status.index].name" /></s:a>
>
> So now when the file name is clicked, it will automatically show the file
> content in a new page.
>
> Can anyone suggest how I can open a SaveAs dialog when the file is clicked?
> I look from the web knowing that document.execCommand("SaveAs"); is the
> javascript to open the SaveAs dialog. But I don't know how can I combine
> this in my page. Any suggestion?
>
> Queenie
> --
> View this message in context: http://www.nabble.com/How-to-promt-SaveAs-dialog-when-a-file-is-to-be-downloaded--tp17510502p17510502.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org