I have a file download functionality in my application (the type of file can be TXT, DOCX, PDF, etc.). When I upload a file (for example : file A.pdf), I can download the file normally (the file downloaded is file A.pdf). But if there's a comma in the file name (for example : file,A.pdf), the file downloaded is named telechargerFichier.action which is the name of my action.

Here is the key part of my struts.xml for downloading file :

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

How to solve this problem?

有帮助吗?

解决方案

Use the contentDisposition property with dynamic result

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

Now, create a getter in the action class for fileName

public String getFileName() {
  return fileName;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top