struts输出图片列表_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > struts输出图片列表

struts输出图片列表

 2012/6/1 16:46:38  wanghuanqiu  程序员俱乐部  我要评论(0)
  • 摘要:从数据库中取出图片字节流,并在界面输出图片publicActionForwardphotoList(finalActionMappingmapping,finalActionFormform,finalHttpServletRequestrequest,finalHttpServletResponseresponse){longblobId=Long.parseLong(request.getParameter("blobId"));ServletOutputStreamouts=null
  • 标签:输出 图片 struts
从数据库中取出图片字节流,并在界面输出图片

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");
     }
发表评论
用户名: 匿名