Reputation: 392
Just I am working on web project, In that i need to download a sql file while clicking the link. I tried to find the HttpResponse or HttpServletResponse in controller. Could any one help me to resolve this issue,
@RequestMapping(value = "/downloadFile.htm", method = RequestMethod.GET)
public void toDownloadFile(@RequestParam("fileName") String fileName,
HttpServletResponse response) {
File file = new File(fileName);
if (file != null) {
try {
response.setContentType("application/sql");
// response.setContentLength((new
// Long(file.getLength()).intValue()));
response.setHeader("content-Disposition",
"attachment; filename=" + fileName);
FileCopyUtils.copy(fileName, response.getOutputStream());
} catch (IOException ex) {
LOGGER.error("Exception in toDownloadFile :" + ex);
}
}
}
But in Spring 3 its available, I hope they removed or renamed the HttpServletResponse in Spring 4. Because HttpServeltRequest has been moved to org.springframework.web.context.request.WebRequest. Any one looked into this? Thanks in advance!!!
Upvotes: 0
Views: 453
Reputation: 228
HttpServeltRequest and HttpServletResponse are javax interfaces not spring.
Are your project dependencies set up correctly?
javax.servlet.http.HttpServletResponse
org.springframework.web.context.request.WebRequest has been around for a while and is documented as...
Generic interface for a web request. Mainly intended for generic web request interceptors, giving them access to general request metadata, not for actual handling of the request.
Upvotes: 1