Reputation: 37
I have File object which looks like this
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;
}
Of course there are lot other objects in my struts action response, which I am not listing here.
After the action completes, the filePath will be populated with the actual path of the file where it resides so that the file can be downloaded. I want to display the fileName and filePath in a <s:a>
tag.
Goal is to have href point to filePath. I tried play with OGNL i.e #, %{}, $() and none seems to display the link properly.
Eg:
<s:a href="?????????"> Click to the get the File </s:a>
Upvotes: 1
Views: 665
Reputation: 13734
The question is a bit unclear but from what I understand, you're looking for s:url
tag.
<a href="<s:url value="%{filePath+fileName}"/>">Link</a>
Upvotes: 1
Reputation: 50281
<s:a href="?????????"> Click to the get the File </s:a>
If the file is in an accessible folder:
<s:a href="http://server.with.files.com/path/to/file/fileName.txt">
Click to the get the File
</s:a>
If the file is in a folder that is protected, not accessible, or is inside the webapplication, or comes from a database, etc... you should call an Action (or a Servlet, if not in Struts2), that should read the file, and return a Stream result. Read:
To understand the OGNL syntax, instead, read this answer.
Upvotes: 1