【问题标题】:how to dynamically download a file using struts 2 annotations (passing variable into annotation)如何使用 struts 2 注释动态下载文件(将变量传递到注释中)
【发布时间】:2013-05-17 14:06:35
【问题描述】:

我是 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 应该是getFileName,它的名字是否正确?
  • 真丢脸,我花了好几个小时寻找错误出现在我眼前的时间 =$ 非常感谢它确实有效
  • 新鲜的眼睛通常会立即发现事物 :)

标签: variables annotations struts arguments


【解决方案1】:

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

public String getFileName() { ... }

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    相关资源
    最近更新 更多