1

我有看起来像这样的文件对象

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>标签中显示文件名和文件路径。

目标是让 href 指向 filePath。我尝试使用 OGNL 即 #、%{}、$(),但似乎没有一个可以正确显示链接。

例如:

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

2 回答 2

1

这个问题有点不清楚,但据我了解,您正在寻找s:url标签。

<a href="<s:url value="%{filePath+fileName}"/>">Link</a>
于 2013-12-13T08:14:39.037 回答
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 应用程序内部,或者来自数据库等......你应该调用一个 Action(或一个 Servlet,如果不在 Struts2 中),它应该读取文件,并返回一个 Stream 结果。读:

要了解 OGNL 语法,请阅读此答案

于 2013-12-13T13:43:09.133 回答