[英]download file instead of opening in browser using struts2
I have written a file upload and download in struts2. 我已经在struts2中编写了文件上传和下载。 But while I download the
text.pdf
file that are opened in the browser page, How to I download files instead of open in the browsers page? 但是,当我下载在浏览器页面中打开的
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>
You can force downloading, but you have to do it from the server side : Implement your own endpoint (a servlet, for example) which returns this header along with the requested file: 您可以强制下载,但是必须从服务器端进行下载 :实现自己的端点(例如servlet),该端点将返回此标头以及所请求的文件:
content-disposition: attachment; filename="suggested-filename"
http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html
There are multiple examples provided online for your query. 在线提供了多个示例供您查询。
Please check the following links.. 请检查以下链接。
File Download example -1 文件下载示例-1
File Download example -2 文件下载示例-2
And target="_blank"
is used for creating a new tab, which is not required for your case. target="_blank"
用于创建新标签,您的案例不需要这样做。
Edit: Please show us your struts configuration, so that we can provide a much better answer. 编辑:请向我们展示您的struts配置,以便我们提供更好的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.