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

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

问题描述

即时通讯新到struts 2和IM询问是否有传递变量参数为支柱的方式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的失败调用吸收剂;动态参数的注释工作,因为他们在做XML

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

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

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