Download 不能';在Spring 4中找不到HttpResponse或HttpServletResponse
我正在做一个web项目,因为我需要在单击链接的同时下载一个sql文件。我试图在控制器中找到HttpResponse或HttpServletResponse。谁能帮我解决这个问题Download 不能';在Spring 4中找不到HttpResponse或HttpServletResponse,download,httpresponse,spring-4,Download,Httpresponse,Spring 4,我正在做一个web项目,因为我需要在单击链接的同时下载一个sql文件。我试图在控制器中找到HttpResponse或HttpServletResponse。谁能帮我解决这个问题 @RequestMapping(value = "/downloadFile.htm", method = RequestMethod.GET) public void toDownloadFile(@RequestParam("fileName") String fileName, Ht
@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);
}
}
}
但在Spring3中,它是可用的,我希望他们在Spring4中删除或重命名HttpServletResponse。因为HttpServeltRequest已移动到org.springframework.web.context.request。WebRequest。有人调查过吗?提前感谢 HttpServeltRequest和HttpServletResponse是javax接口,而不是spring 您的项目依赖项设置是否正确
javax.servlet.http.HttpServletResponse
已经存在了一段时间,并记录为
web请求的通用接口。主要用于通用web请求拦截器,使其能够访问通用请求元数据,而不是实际处理请求