//////////////////////cwry_pic.jsp///////////////////////// 
<%@page import="java.io.*"%> 
<%@page import="com.jagie.business.profile.*" %> 
<%@page import="java.sql.Blob"%> 
<% 
response.reset(); 
//这个设置很重要,否则客户端浏览器不能识别输出内容,导致弹出下载的对话框。 
response.setContentType("image/jpeg"); 
ServletOutputStream sos = response.getOutputStream(); 
//这里是用hibernate来根据id装载对象,你可以用别的方式如jdbc来组装对象,附文中有 
//BaseInfo这个javabean的示意性代码. 
BaseInfo bif= ProFileOperator.loadProFile(Long.valueOf("1")); 
//输出图片 
if(bif!=null&&bif.getPic()!=null){ 
Blob blob=(Blob)bif.getPic(); 
InputStream pi = blob.getBinaryStream(); 
int blobsize = (int)blob.length(); 
byte[] blobbytes = new byte[blobsize]; 
int bytesRead = 0; 
while ((bytesRead = pi.read(blobbytes)) != -1) { 
sos.write(blobbytes, 0, bytesRead); 

pi.close(); 
sos.flush(); 

%> 

解决方案 »

  1.   

    response.setContentType("image/jpeg");这句代码好象有问题哦!你把他写在jsp页面里面,怎样把import javax.servlet.http.HttpServletresponse包进来啊.你最好把他写在一个bean里面.用Struts实现.
      

  2.   

    回复人: gewenhui(葛文辉) ( ) 信誉:100  2005-04-14 16:13:00  得分: 0  
     
     
       response.setContentType("image/jpeg");这句代码好象有问题哦!你把他写在jsp页面里面,怎样把import javax.servlet.http.HttpServletresponse包进来啊.你最好把他写在一个bean里面.用Struts实现.
      
     -----------------------------------------------------------------------
    谢谢!
    是这句错了吗?我感觉出的错不象是这句导致的啊。还有别的意见吗?