Pradeep
Pradeep

Reputation: 71

download file instead of opening in browser using struts2

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

Answers (3)

Pradeep
Pradeep

Reputation: 71

enter image description here

I have uploaded the image that contain the struts configuration file.

Upvotes: 0

shiva kumar
shiva kumar

Reputation: 121

There are multiple examples provided online for your query.

Please check the following links..

File Download example -1

File Download example -2

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

Little Santi
Little Santi

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

Related Questions