本文共 1921 字,大约阅读时间需要 6 分钟。
在开发ERP系统下载模板问题时,控制台报错如下:
File "/webpage/a/mds/mdsquota/mdsQuotaDetail/template.jsp" not found
出现这个问题的原因是因为controller中用了两次response响应到前台来。
出错前代码如下:
@RequiresPermissions("mds:mdsquota:mdsQuota:import") @RequestMapping(value = "template") public String getFileTemplate(String id,HttpServletResponse response,RedirectAttributes redirectAttributes) { try { String fileName ="材料定额数据导入模板.xlsx"; String title="红色字体为必填字段,序号和单台定额必须为整数,备注信息不能超过50个字"; ListheaderList = new ArrayList<>(); //示例数据 List exampleList = new ArrayList<>(); new ExportExcel().insertList(headerList, exampleList).createExcel(title,headerList,exampleList).write(response,fileName).dispose(); addMessage(redirectAttributes,"模板下载成功"); } catch (Exception e) { addMessage(redirectAttributes,"模板下载失败!失败信息:"+e.getMessage()); } return "redirect:"+Global.getAdminPath()+"/mds/mdsquota/mdsQuota/edit?id="+id; }
在这段代码中 最后发起转发前,程序已经通过response(new ExportExcel().insertList(headerList, exampleList).createExcel(title,headerList,exampleList).write(response,fileName).dispose();),响应到了前端,所以发生了控制台那样的报错。
最后还是在转发之前发通过return null,解决的报错。
@RequiresPermissions("mds:mdsquota:mdsQuota:import") @RequestMapping(value = "template") public String getFileTemplate(String id,HttpServletResponse response,RedirectAttributes redirectAttributes) { try { String fileName ="材料定额数据导入模板.xlsx"; String title="红色字体为必填字段,序号和单台定额必须为整数,备注信息不能超过50个字"; ListheaderList = new ArrayList<>(); //示例数据 List exampleList = new ArrayList<>(); new ExportExcel().insertList(headerList, exampleList).createExcel(title,headerList,exampleList).write(response,fileName).dispose(); addMessage(redirectAttributes,"模板下载成功"); return null; } catch (Exception e) { addMessage(redirectAttributes,"模板下载失败!失败信息:"+e.getMessage()); } return "redirect:"+Global.getAdminPath()+"/mds/mdsquota/mdsQuota/edit?id="+id; }
转载地址:http://lcfoi.baihongyu.com/