Dima
Dima

Reputation: 1794

How to implement file download with Spring MVC in Java?

There is a lot upload examples, but I couldn't find any for download. I'm using Spring 3.0 and I need to generate some text buffer and then let user download it as a file. (There is no static resource.)

So far I've tried to use @ResponseBody and writing to response output stream. In both cases browser display content of the 'file' instead of showing Save dialog box. How do I make browser display a dialog box?

Thanks.

Upvotes: 4

Views: 1598

Answers (1)

Maurício Linhares
Maurício Linhares

Reputation: 40333

You have to set the Content-Disposition header at your action (and not only the response body):

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

Upvotes: 1

Related Questions