jsp getOutputStream() has already been called for this response异常解决方法

添加以下两段代码即可,我是在用jsp输出图像的时候出现这个问题

out.clear();
out = pageContext.pushBody();

附上我的输出图像的JSP代码

<%@ page info="Random Image Show" pageEncoding="UTF-8" contentType="image/jpg" autoFlush="true" buffer="16kb" session="false"
	import="java.io.FileInputStream"%>
<%
	ServletOutputStream sos = null;
	if (sos == null) sos = response.getOutputStream();
	FileInputStream fis = new FileInputStream((String) request.getAttribute("filename"));
	byte[] buf = new byte[1024]; //缓冲区大小  
	int len = 0;
	while ((len = fis.read(buf)) != -1) {
		sos.write(buf, 0, len);
	}
	sos.flush();
	sos.close();
	fis.close();
	out.clear();
	out = pageContext.pushBody();
%>



fatkun

没有评论


You can leave the first : )



发表评论

电子邮件地址不会被公开。