日期:2014-05-18  浏览次数:20688 次

高分求高手 帮忙解决问题!!
1.我的图片已以2进制保存到了SQL数据库
有如下几个字段   id   name   age   image
2.我想将   该SQL   内容   用JSP   在WEB页面以这种样式显示出来:
id       name       age     image
1         li           22         图片1
2         xiao       23         图片2
。       。。     。。     。。。       注意   图片是要对应的

3.我写了一个   image.jsp用来显示
。。。。
%>
<tr>
        <td>
<%=rs.getInt( "id ")%>
</td>
<td   height= "76 ">
<%=rs.getString(3)%>
</td>
<td>
<%=rs.getString(4)%>
</td>
<td>
<img   height=72   src= "testimageout.jsp? "   width=136   > </td>
<%       }
}catch(SQLException   e)   {}
%> 其中testimageout.jsp是处理输出流   如下
。。。。

String   sql   =   "select   image   from   picturenews ";  
rs=stmt.executeQuery(sql);
while(rs.next())   {
ServletOutputStream   sout   =   response.getOutputStream();
InputStream   in   =   rs.getBinaryStream( "image ");
byte   b[]   =   new   byte[0x7a120];
for(int   i   =   in.read(b);   i   !=   -1;)
{
sout.write(b);  
in.read(b);
}
sout.flush();
sout.close();
}
%>
但是出现的问题   是运行   image.jsp后   图片显示的确是一样的   如下
id       name       age     image
1         li           22         图片1         *
2         xiao       23         图片1         *
  都是图片1

望高手帮忙解决   该问题   谢谢  




------解决方案--------------------
你要根据id来取图片

int id = Integer.parseInt(request.getParameter( "id "));
String sql = "select image from picturenews where id = "+id ;

<img height=72 src= "testimageout.jsp? " width=136 >
改成
<img height=72 src= "testimageout.jsp?id=rs.getInt( "id ") " width=136 >

------解决方案--------------------
<img height=72 src= "testimageout.jsp?id= <%=rs.getInt( "id ")%> " width=136 > </td>

==================

int id = Integer.parseInt(request.getParameter( "id "));
String sql = "select image from picturenews where id = "+id ;
rs=stmt.executeQuery(sql);
while(rs.next()) {
ServletOutputStream sout = response.getOutputStream();
InputStream in = rs.getBinaryStream( "image ");
byte b[] = new byte[0x7a120];
for(int i = in.read(b); i != -1;)
{
sout.write(b);
in.read(b);
}
sout.flush();
sout.close();
}
这样子不行吗