2013-12-13 30 views
1

我有File對象,它看起來像這樣如何設置Struts 2的對象一個Struts 2標籤內(A HREF)

public class FileTO implements Serializable{ 
private String fileName; 
private String filePath; 

public String getFileName() { 
    return fileName; 
} 

public void setFileName(String fileName) { 
    this.fileName = fileName; 
} 

public String getFilePath() { 
    return filePath; 
} 

public void setFilePath(String filePath) { 
    this.filePath = filePath; 
} 

當然也有我的Struts動作響應很多其他對象,我不在這裏列出。 操作完成後,filePath將填充它駐留的文件的實際路徑,以便可以下載該文件。我想在<s:a>標記中顯示fileName和filePath。

目標是讓href指向filePath。我嘗試過使用OGNL,例如#,%{},$(),而且似乎都沒有正確顯示鏈接。

如:

<s:a href="?????????"> Click to the get the File </s:a> 
+0

你能提供你的動作類代碼嗎? –

回答

1

的問題是有點不清楚,但是從我的理解,你正在尋找s:url標籤。

<a href="<s:url value="%{filePath+fileName}"/>">Link</a> 
+0

謝謝..這幾乎解決了我的問題。 –

1
<s:a href="?????????"> Click to the get the File </s:a> 
  1. 如果該文件是可訪問的文件夾:

    <s:a href="http://server.with.files.com/path/to/file/fileName.txt"> 
        Click to the get the File 
    </s:a> 
    
  2. 如果文件是受保護的,不可訪問的文件夾中,或者在Web應用程序中,或者來自數據庫等等......你應該調用一個Acti (或者Servlet,如果不在Struts2中),它應該讀取文件,並返回一個Stream結果。閱讀:

要理解OGNL語法,而是read this answer