当前位置: 代码迷 >> Java Web开发 >> 关于把byte[]还原成图片的.关键是不经过磁盘,该怎么处理
  详细解决方案

关于把byte[]还原成图片的.关键是不经过磁盘,该怎么处理

热度:192   发布时间:2016-04-17 12:28:59.0
关于把byte[]还原成图片的...关键是不经过磁盘
请看题.
我现在已经把byte[]类型从oracle里面取出来了.
我想直接在servlet里面让图片显示(关键是必须不经过磁盘.在jsp里面显示也可以的.)
各位都什么高见啦.
Java code
    public void doGet(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        String adname=request.getParameter("adname");        ApplicationContext App=WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());        AdDao adDao=(AdDao)App.getBean("adDao");        Ad ad=adDao.findAd(adname);        byte images[]=ad.getAdimage();                response.setContentType("image/jpeg");           InputStream in=new ByteArrayInputStream(images);        OutputStream toClient=response.getOutputStream();             int len;        byte[] buf=new byte[1024];           while((len =in.read(buf,0,1024))!=-1){           toClient.write(buf,0,len);           }        toClient.close();        


上面写的好像是对的.但是就是显示不了.
请各位高人指点指点.

------解决方案--------------------
网站是我的,有事没事多联系吧!
  相关解决方案