【问题标题】:File download issue: comma in the file name in Struts 2文件下载问题:Struts 2 中文件名中的逗号
【发布时间】:2014-01-20 16:37:48
【问题描述】:

我的应用程序中有文件下载功能(文件类型可以是 TXT、DOCX、PDF 等)。当我上传文件时(例如:file A.pdf),我可以正常下载文件(下载的文件是file A.pdf)。但如果文件名中有逗号(例如:file,A.pdf),则下载的文件名为telechargerFichier.action,这是我的操作名称。

这是我的struts.xml 用于下载文件的关键部分:

<action name="telechargerFichier" class="documentAction" method="telechargerFichier">      
    <result name="success" type="stream">
        <param name="contentType">application/octet-stream</param>
        <param name="inputName">fileInputStream</param>
        <param name="bufferSize">1024</param>
    </result>
</action>  

如何解决这个问题?

【问题讨论】:

    标签: java download configuration struts2 ognl


    【解决方案1】:

    contentDisposition 属性用于动态结果

    <param name="contentDisposition">attachment;filename="${fileName}"</param>
    

    现在,在 fileName 的操作类中创建一个 getter

    public String getFileName() {
      return fileName;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-03
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      • 2019-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多