EXCEL导出时遇到的Cannot forward after response has been committed

java.lang.IllegalStateException:Cannot forward after response has been committed 异常


http://blog.csdn.net/fenglibing/article/details/4106564


原因是调用了两次response



response.setContentType("application/vnd.ms-excel");
response.setContentType("UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + getFileName() + ".xls");
os = response.getOutputStream();
wb.write(os);
return null;//这里原来写的是return mapping.findForward(SUCCESS);,所以报了这个异常

public String getFileName() throws Exception {
StringBuffer fileName = new StringBuffer("文件名-");
Date date = Calendar.getInstance().getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HHmmss");
fileName.append(sdf.format(date));
return new String(fileName.toString().getBytes("GBK"), "ISO-8859-1");

}

你可能感兴趣的:(EXCEL导出时遇到的Cannot forward after response has been committed)