how to dynamically download a file using struts 2 annotations (passing variable into annotation)

扶醉桌前 提交于 2020-01-16 19:07:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!