只是我正在处理网络项目,因为我需要在单击链接时下载一个 sql 文件。我试图在控制器中找到HttpResponse或HttpServletResponse 。谁能帮我解决这个问题,
@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);
}
}
}
但是在 Spring 3 中它可用,我希望他们在 Spring 4 中删除或重命名了 HttpServletResponse。因为HttpServeltRequest已移至 org.springframework.web.context.request。网络请求。有人调查过这个吗?提前致谢!!!