1.在项目中JSP页面输出流显示为图片时,刷新时,报以下错误
getOutputStream() has already been called for this response
index.jsp
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<TABLE>
<TR>
<TD></TD>
</TR>
<TR>
<TD><img src="show.jsp"></TD>
</TR>
</TABLE>
</BODY>
</HTML>
show.jsp
<%@ page contentType="text/html; charset=gbk" %>
<%@ page import="java.io.*"%>
<%@ page import="cn.com.hnisi.visio.image.*"%>
<%
VisioDemo v=new VisioDemo();
v.setVisible(false);
try
{
byte[] image = v.getVisio().createPreview(new File("E:/test/test.vsd"));
response.setContentType("image/jpeg");
OutputStream outs = response.getOutputStream();
outs.write(image);
outs.flush();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
%>
出现错误原因是response的数据流没有释放
解决办法
<%@ page contentType="text/html; charset=gbk" %>
<%@ page import="java.io.*"%>
<%@ page import="cn.com.hnisi.visio.image.*"%>
<%
VisioDemo v=new VisioDemo();
v.setVisible(false);
try
{
byte[] image = v.getVisio().createPreview(new File("E:/test/test.vsd"));
response.setContentType("image/jpeg");
OutputStream outs = response.getOutputStream();
outs.write(image);
outs.flush();
outs=null;
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
%>