我想在JSP页中显示存储在ORACLE数据库中的图片
并且想在一个页面显示多张,即对应数据库中的多条记录值.
另外:请注意,我用的struts框架,希望大家所给出解决方式也是采用struts标签来作,同时希望给出具体的代码示例。多谢多谢!500分!,如果你解决了,请到java板块的其他小类(web开发,j2se基础类,j2se扩展类,j2EE,框架开源)里面可以看到我的同样的帖子,就可以接分了,谢谢!!!
并且想在一个页面显示多张,即对应数据库中的多条记录值.
另外:请注意,我用的struts框架,希望大家所给出解决方式也是采用struts标签来作,同时希望给出具体的代码示例。多谢多谢!500分!,如果你解决了,请到java板块的其他小类(web开发,j2se基础类,j2se扩展类,j2EE,框架开源)里面可以看到我的同样的帖子,就可以接分了,谢谢!!!
String idStr = request.getParameter("id");
int id = Integer.parseInt(idStr);
byte[] buffer = weigh.getSecondPicture(id);
if (buffer == null) buffer = new byte[1];
response.setContentType("image/jpg");
OutputStream sout = response.getOutputStream();
int len = buffer.length;
//System.out.println(len);
sout.write(buffer, 0, len);
sout.flush();
sout.close();
} catch (Exception e) {
System.out.println(e);
}
1.在BusinessBean中读出数据库中的路径
ArrayList arrImgPath = new ArrayList();
while(rs.next()){
arrImgPath.add(rs.getString("Img_Path"));
}
request.setAttribute("imgpath",arrImgPath);
2.在jsp中调用BusinessBean showImg.显示
<%@ taglib uri="struts-logic" prefix="logic" %>
<logic:iterate id="element1" name="element" scope="request">
<html:img page="/showImg.do" paramId="img" paramName="element1" border="1" width="108" height="26" scope="request"/>
</logic:iterate>
3.BusinessBean showImg.java:
String imgPath=request.getParameter("img");
file = new File(imgPath);
if (!file.isDirectory()&& file.exists()){
length = (int)file.length();
}
res.setContentType("image/"+suffix);
res.setHeader("Content-Disposition","inline");
res.setContentLength(length);
if (length > 0){
int bufferSize = 32768;
InputStream in = new FileInputStream(fullpath);
ServletOutputStream outfile = res.getOutputStream();
int chunkLen = bufferSize;
if(chunkLen > length && length > 0)
chunkLen = length;
byte ioBuf[] = new byte[chunkLen];
do{
chunkLen = in.read(ioBuf);
if(chunkLen <= 0)
break;
outfile.write(ioBuf, 0, chunkLen);
length -= chunkLen;
} while(length != 0);
in.close();
outfile.flush();
outfile.close();
}
改为res.setContentType("image/jpg");或者....