从数据库中取出图片字节流,并在界面输出图片
public ActionForward photoList(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response)
{
long blobId = Long.parseLong(request.getParameter("blobId"));
ServletOutputStream outs = null;
BufferedOutputStream bos = null;
try {
outs = response.getOutputStream();
BlobService blobService = (BlobService)getBean("BlobService");
BlobVO b=blobService.getBlobByOid(blobId);
int blobsize = (int)b.getContent().length;
response.setContentType("image/jpeg;charset=GB2312");
response.setHeader("Content-Transfer-Encoding","base64");
bos = new BufferedOutputStream(outs);
bos.write(b.getContent(),0,blobsize);
bos.flush();
} catch (IOException e) {
e.printStackTrace();
}
finally{
try {
if(bos!=null)
bos.close();
if(outs!=null)
outs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return mapping.findForward("photo");
}
public ActionForward photoList(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response)
{
long blobId = Long.parseLong(request.getParameter("blobId"));
ServletOutputStream outs = null;
BufferedOutputStream bos = null;
try {
outs = response.getOutputStream();
BlobService blobService = (BlobService)getBean("BlobService");
BlobVO b=blobService.getBlobByOid(blobId);
int blobsize = (int)b.getContent().length;
response.setContentType("image/jpeg;charset=GB2312");
response.setHeader("Content-Transfer-Encoding","base64");
bos = new BufferedOutputStream(outs);
bos.write(b.getContent(),0,blobsize);
bos.flush();
} catch (IOException e) {
e.printStackTrace();
}
finally{
try {
if(bos!=null)
bos.close();
if(outs!=null)
outs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return mapping.findForward("photo");
}