Reputation: 71
I have written a file upload and download in 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?
<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>
Upvotes: 1
Views: 1823
Reputation: 71
I have uploaded the image that contain the struts configuration file.
Upvotes: 0
Reputation: 121
There are multiple examples provided online for your query.
Please check the following links..
And target="_blank"
is used for creating a new tab, which is not required for your case.
Edit: Please show us your struts configuration, so that we can provide a much better answer.
Upvotes: 2
Reputation: 8783
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:
content-disposition: attachment; filename="suggested-filename"
http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html
Upvotes: 2