简体   繁体   中英

How to change the file name to be downloaded

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 .

Replace ${fileName} with a fixed string:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM