如何使用struts 2注释动态下载文件(将变量传递给注释) [英] how to dynamically download a file using struts 2 annotations (passing variable into annotation)

查看:24
本文介绍了如何使用struts 2注释动态下载文件(将变量传递给注释)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 struts 2 的新手,我在问是否有办法将变量参数传递给 struts 2 注释.

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

我在网上搜索,但我只找到了 xml Struts 的解决方案,这不是我想要的 =(

i searched on the net but i found only solutions with xml Struts and that is not what i want =(

推荐答案

你的文件名 getter 方法命名错误,应该遵循 JavaBean 模式:

Your filename getter method is named incorrectly, it should follow the JavaBean pattern:

public String getFileName() { ... }

OGNL 未能调用 getter;动态参数在注释中的作用与在 XML 中的作用一样.

OGNL's failing to call the getter; dynamic parameters work in annotations as they do in XML.

这篇关于如何使用struts 2注释动态下载文件(将变量传递给注释)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆