STUTS2 下载 getOutputStream() has already been called for this response异常的原因_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > STUTS2 下载 getOutputStream() has already been called for this response异常的原因

STUTS2 下载 getOutputStream() has already been called for this response异常的原因

 2012/9/8 11:52:12  CHEEN  程序员俱乐部  我要评论(0)
  • 摘要:publicStringexcel()throwsException{initRequest();//查询IDStringqueryId=request.getParameter("queryId");RequestParamtersrequestParamters=newRequestParamters(request,false);HSSFWorkbookwb=null;try{wb=publicSrv.excel(queryId,getSqlColumns(queryId)
  • 标签:for has all 下载 原因 异常
public String excel() throws Exception{
		initRequest();
		//查询ID
		String 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;
	}

如果action的返回写成
return SUCCESS;
在tomcat6.0.14的版本会出现
getOutputStream() has already been called for this response
,在tomcat6.0.28中没有,解决办法是action最后必须是
return null;
发表评论
用户名: 匿名