小编Tus*_*har的帖子

我得到一个异常:java.lang.IllegalStateException:已经为此响应调用了getOutputStream()

我想编写代码来下载一个存储在我系统中的文件

这是我的代码:

在控制器类中,我有以下映射

@RequestMapping(value = "/processFile", method = RequestMethod.POST)
    public @ResponseBody ModelAndView downloadFileProcess(
            @RequestParam("file") File originalFile,
            @RequestParam("action") String action, HttpServletResponse response) {

        ModelAndView model = new ModelAndView();
        model.setViewName("error");
        System.out.println("");
        System.out.println("Action: "+action);
        model.addObject("message", "Action:" + action);
        try {
            utility.downloadFile(originalFile, response);
            message = "The file was downloaded successfully";

        } catch (IOException e) {
            e.printStackTrace();
            message = "The process failed due to following reason: "
                    + e.getMessage();
        } catch (Exception e) {
            e.printStackTrace();
            message = "The process failed due to following reason: " …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc spring-boot

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

java ×1

spring-boot ×1

spring-mvc ×1