2015-10-10 104 views
1

我寫了一個文件上傳和下載在struts2。 但是,當我下載在瀏覽器頁面中打開的text.pdf文件時, 如何下載文件而不是在瀏覽器頁面中打開?下載文件,而不是在瀏覽器中使用struts2打開

<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> 
+0

這可能是瀏覽器特定的設置。 –

回答

0

enter image description here

我已上傳了包含Struts配置文件中的圖像。

+0

編輯您的問題。不要將代碼/ conf作爲圖像發佈。 –

2

您可以強制下載,但你必須從服務器端做:實現自己的端點(一個servlet,例如),其與所請求的文件一起返回這個頭:

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

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

2

在線提供了多個用於查詢的示例。

請查看以下鏈接..

File Download example -1

File Download example -2

而且target="_blank"用於創建一個新的標籤,它不需要你的情況。

編輯:請向我們展示您的struts配置,以便我們提供更好的答案。

相關問題