How to implement file upload using Spring MVC in Java?

There are many download examples, but I could not find them to download. I am using Spring 3.0, and I need to generate some text buffer, and then allow the user to load it as a file. (There is no static resource.)

So far, I have been trying to use @ResponseBody and write to the output stream of the response. In both cases, the browser displays the contents of the "file" instead of displaying the "Save" dialog box. How to make a dialog a browser browser?

Thanks.

+4
source share
1 answer

You must set the Content-Disposition header in your action (and not just the response body):

 Content-Disposition: attachment; filename=your-file.pdf 
+1
source

Source: https://habr.com/ru/post/1387370/


All Articles