如何使用struts2注释动态下载文件(将变量传递到注释中)



我是struts 2的新手,我想知道是否有一种方法可以将变量参数传递到struts 2注释中。

这是我已经做过的,但没有运气

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;
   }
}

我在网上搜索,但我发现只有解决方案与xml Struts,这不是我想要的=(

文件名getter方法命名不正确,它应该遵循JavaBean模式:

public String getFileName() { ... }

OGNL调用getter失败;动态参数在注释中的作用和在XML中的作用一样。

最新更新