How to change the file name to be downloaded

。_饼干妹妹 提交于 2019-12-08 13:54:30

问题


Here is I have the result:

<result name="success" type="stream">
   <param name="contentDisposition">attachment;filename="${fileName}"</param>
</result>

How it works now: if my fileName is "raghu.txt" in DB it will be downloaded as raghu.txt

What I want: regardless of fileName the output name should be ravi.txt.


回答1:


Try in your action

public String getFileName() {
  return "ravi.txt";
}

When result is executed it will get the dynamic parameter via this method, and it will return the value wanted. But, it's only to show you how dynamic parameters work, actually if the configuration used the dynamic parameter you should modify the action code and setFileName("ravi.txt"); before the result code is returned. Then you can remain the normal getter.




回答2:


Replace ${fileName} with a fixed string:

<result name="success" type="stream">
   <param name="contentDisposition">attachment;filename="ravi.txt"</param>
</result>


来源:https://stackoverflow.com/questions/18825308/how-to-change-the-file-name-to-be-downloaded

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