0

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!!!

4

1 に答える 1

1

HttpServeltRequest と HttpServletResponse は、Spring ではない javax インターフェイスです。

プロジェクトの依存関係は正しく設定されていますか?

javax.servlet.http.HttpServletResponse

org.springframework.web.context.request.WebRequestはしばらく前から存在しており、次のように文書化されています...

Web 要求の汎用インターフェース。主に、一般的な Web リクエスト インターセプターを対象としており、リクエストの実際の処理ではなく、一般的なリクエスト メタデータへのアクセスを提供します。

于 2014-02-14T09:24:02.557 に答える