`
CHEEN
  • 浏览: 134438 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

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

阅读更多
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;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics