file download in spring mvc
in my home page I want to display user guide in two different format ( pdf and word) these documents were already created by technica开发者_运维技巧l writers and I want to show the download links to these documents in home page after the user successfully logged in. I can achieve this easily by putting these two documents in one folder up to the 'WEB-INF' but it will enable anyone can download these files(without logging in). Could you advise whats the best way to handle this in spring mvc 2.5
I guess you already have some security support, so you can check whether user is logged in inside a controller code.
Then you can put your files into /WEB-INF
folder and create a special controller for serving these files to the logged users. This controller will check that user is logged in and then forward a request to the target file. In typical Spring MVC configurations you can forward a request by returning something like forward:/WEB-INF/myFile.pdf
as a view name.
Alternatively, if you use some security library, such as Spring Security, you can use its features to secure access to your files. In that case you don't need to put them into /WEB-INF
and implement a specifal controller for accessing them.
精彩评论