How to download files using spring MVC in Java?

There are many upload examples, but I can't find any downloads I'm using spring 3.0. I need to generate some text buffers and let users download them as files (no static resources.)

So far, I have tried to use @ ResponseBody and write the response output stream In both cases, the browser displays the contents of the file instead of the save dialog box How do I make my browser display dialog boxes?

thank you.

Solution

You must set the content disposition header (not just the response body) in the operation:

Content-Disposition: attachment; filename=your-file.pdf
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>