Search code examples
javajspstruts2ognlstruts-tags

How to set Struts 2 object inside a Struts 2 tag (a href)


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>

Solution

  • 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>