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