getOutputStream() has already been called for this response问题
求助报错:
org.apache.jasper.JasperException: getOutputStream() has already been called for this response
at org.apache.jasper.servlet.JspServletWrapper.handle
JspException(JspServletWrapper.java:460)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:367)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
jsp:
<%CustServSpecTool export=new CustServSpecTool();
try {
export.exportSpec(request,response);
out.flush();
out.clear();
out = pageContext.pushBody();
} catch(Exception e) {
e.printStackTrace();
out.println("Download template Error:"+e.toString());
}
%>
java:
public void exportSpec(HttpServletRequest request,HttpServletResponse response) throws Exception {
String result= "";
....
...
//System.out.println("result:" + result);
try{
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=\"cfs.xml\"");
response.getOutputStream().write(result.getBytes("GBK"));
response.getOutputStream().flush();
}catch(Exception e){
e.printStackTrace();
}
}
------解决方案--------------------又看了一下你的代码,看出问题来了。你在jsp中调用exportSpec 这个方法,这个方法中调用getOutPutStream,实际上此时的JSP本身也会调用getOutPutStream来输出脚本,所以两者冲突报错了。考虑这一点,你完全可以用一个servlet来实现。