问题
im new to struts 2 and im asking if there's a way to pass a variable argument into struts 2 annotation.
here is what i already did but with no luck
public class DownloadFileAction extends ModuleGenericClass{
private InputStream inputStream;
private String fileName;
@Action(value="/downloadFile",results={
@Result(name="success",type="stream",params = {
"contentType",
"application/octet-stream",
"inputName","inputStream",
"bufferSize","1024","contentDisposition",
"filename=\"${fileName}\""})
})
public String execute() throws Exception {
fileName = "testing";
inputStream = //myInputStream
return SUCCESS;
}
public void setCourrierId(String courrierId) {
this.courrierId = courrierId;
}
public String getfileName() {
return fileName;
}
public void setfileName(String fileName) {
this.fileName = fileName;
}
public InputStream getInputStream() {
return inputStream;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
}
i searched on the net but i found only solutions with xml Struts and that is not what i want =(
回答1:
Your filename getter method is named incorrectly, it should follow the JavaBean pattern:
public String getFileName() { ... }
OGNL's failing to call the getter; dynamic parameters work in annotations as they do in XML.
来源:https://stackoverflow.com/questions/16611088/how-to-dynamically-download-a-file-using-struts-2-annotations-passing-variable