从数据库取图片报错!请教各位!在线等!

jianyu807 2004-04-14 11:59:02
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page language="java"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import="hfmis.ConnDbBean"%>

<html>
<head>
<title>
photo
</title>
</head>
<body bgcolor="#ffffff">
<jsp:useBean id="ConnDbBean" scope="request" class="hfmis.ConnDbBean"/>
<%
try{
String strid = request.getParameter("strid");

String sql = "";
ResultSet rs = null;
sql = "select Photo from Employee where EmployeeID = '"+strid+"'";
rs = ConnDbBean.executeQuery(sql);
rs.first();

InputStream ins = rs.getBinaryStream("Photo");
response.reset();
response.setContentType("image/gif");
byte[] b = new byte[1024];
int len;

while((len=ins.read(b)) > 0){
response.getOutputStream().write(b,0,len);
}
response.getOutputStream().flush();
response.getOutputStream().close();
ins.close();
rs.close();
}
catch(Exception e){

}
%>
</body>
</html>
这是我的取图片的jsp!能成功取到图片!可是每取一次就报错:
StandardWrapperValve[debugjsp]: Servlet.service() for servlet debugjsp threw exception

java.lang.IllegalStateException: getOutputStream() has already been called for this response

java.lang.IllegalStateException: getOutputStream() has already been called for this response
请问各位大哥是什么错!!
我在jb9上发布时能取到图片!但在独立的tomcat4.1上就不能取到图了!!
在线等哈!
谢谢!
...全文
60 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
jianyu807 2004-04-30
  • 打赏
  • 举报
回复
没人来看么???
jianyu807 2004-04-16
  • 打赏
  • 举报
回复
我找到原因了
http://www.gyro.cn/view.php/node_18_17.htm
大家来看看怎么解决呀!!!
ddmcx2002 2004-04-14
  • 打赏
  • 举报
回复
这个问题基本上是很难。
up
CoolAbu 2004-04-14
  • 打赏
  • 举报
回复
response.getOutputStream().close();
这个把它注释掉试试

不行再把Try和Catch也去掉 试
cocosunshine 2004-04-14
  • 打赏
  • 举报
回复
jdbc读图片很麻烦~~
jianyu807 2004-04-14
  • 打赏
  • 举报
回复
还是不行呀!!
jianyu807 2004-04-14
  • 打赏
  • 举报
回复
哦!我看看哈!
CoolAbu 2004-04-14
  • 打赏
  • 举报
回复
还有情况是你的页面中有空格,把所有<%%>外的空格全部去掉。
CoolAbu 2004-04-14
  • 打赏
  • 举报
回复
大概原因,是因为你这个页面设置了两次 contentType

解决方法:
1、用Servlet
把你显示图片的页面用Servlet来做,这样只用设置一次Contenttype就可以了。

2、用JSP
把你那些代码全部加到一个Try里面,然后再Catch里面不打印异常
gxh 2004-04-14
  • 打赏
  • 举报
回复
把response.getOutputStream()取回放在一個OutputStream試試。
看出錯的提示,好象在你使用的環境中,response.getOutputStream只能調用一次。
jianyu807 2004-04-14
  • 打赏
  • 举报
回复
高手来看看呀!
jianyu807 2004-04-14
  • 打赏
  • 举报
回复
有没哪位大哥知道呀??

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧