0

只是我正在处理网络项目,因为我需要在单击链接时下载一个 sql 文件。我试图在控制器中找到HttpResponseHttpServletResponse 。谁能帮我解决这个问题,

@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。网络请求。有人调查过这个吗?提前致谢!!!

4

1 回答 1

1

HttpServeltRequest 和 HttpServletResponse 是 javax 接口而不是 spring。

您的项目依赖项设置是否正确?

javax.servlet.http.HttpServletResponse

org.springframework.web.context.request.WebRequest已经存在了一段时间,并被记录为...

Web 请求的通用接口。主要用于通用 Web 请求拦截器,使它们能够访问通用请求元数据,而不是用于实际处理请求。

于 2014-02-14T09:24:02.557 回答