繁体   English   中英

下载文件,而不是使用struts2在浏览器中打开

[英]download file instead of opening in browser using struts2

我已经在struts2中编写了文件上传和下载。 但是,当我下载在浏览器页面中打开的text.pdf文件时,如何下载文件而不是在浏览器页面中打开?

<div class="block-fluid table-sorting clearfix">
    <table cellpadding="0" cellspacing="0" width="100%" class="table" id="tSortable">
        <thead>
            <tr>
                <th>S. No</th>
                <th>ACCOUNT NO</th>
                <th>FILE </th>
                <th>ACTION</th>
            </tr>
        </thead>
        <tbody>
            <s:iterator value="fileuploadlist" status="rowstatus" >
                <tr>                           
                    <td><s:property value="#rowstatus.index+1" /></td>
                    <td><s:property value="fileupload_temp2" /></td>
                    <td><s:property value="fileupload_filename"/></td>                                    
                    <td><s:a href="%{fileupload_filepath}" target="_blank" >download</s:a> </td>

                </tr>
            </s:iterator>
        </tbody>
    </table>
</div>

您可以强制下载,但是必须从服务器端进行下载 :实现自己的端点(例如servlet),该端点将返回此标头以及所请求的文件:

content-disposition: attachment; filename="suggested-filename"

http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html

在线提供了多个示例供您查询。

请检查以下链接。

文件下载示例-1

文件下载示例-2

target="_blank"用于创建新标签,您的案例不需要这样做。

编辑:请向我们展示您的struts配置,以便我们提供更好的答案。

在此处输入图片说明

我已经上传了包含struts配置文件的图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM