STUTS2 下载 getOutputStream() has already been called for this response异常的原因
public String excel() throws Exception{initRequest();//查询IDString queryId = request.getParameter("queryId");RequestParamters requestParamters = new RequestParamters(request, false);HSSFWorkbook wb = null;try {wb = publicSrv.excel(queryId, getSqlColumns(queryId), requestParamters);} catch (Exception ex) {ex.printStackTrace();}HttpServletResponse response = getResponse();OutputStream os = null;try {QueryConfig queryConfig = ConfigQuery.getQueryConfig(queryId);String title = null;if(null != queryConfig){title = queryConfig.getExcelTitle();}if(StrUtils.isEmpty(title)){title = "无标题";}os = response.getOutputStream();// 取得输出流response.reset();// 清空输出流response.setHeader("Content-disposition","attachment;filename="+new String((title).getBytes(),"ISO8859_1")+".xls");// 设定输出文件头response.setContentType("application/msexcel");// 定义输出类型wb.write(os);} catch (Exception e) {e.printStackTrace();}finally{try {os.flush();os.close();} catch (IOException e) {}}return null;}
return SUCCESS;在tomcat6.0.14的版本会出现
getOutputStream() has already been called for this response,在tomcat6.0.28中没有,解决办法是action最后必须是
return null;