java-byte[]图片在页面展示

    public void img(HttpServletRequest req, HttpServletResponse res) {
        //res.setHeader("Content-Type", "image/jpeg");
        //String reportType = req.getParameter("reportType");
        String reportIdstr = req.getParameter("reportIdstr");
        String pageIdstr = req.getParameter("pageIdstr");
        String dataKey = req.getParameter("dataKey");
        FbReportData data = null;
        try {
            data = this.fbReportDataService.findByReportIdAndPageIdAndDataKey(reportIdstr, pageIdstr, dataKey);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(data!=null){
            InputStream in = new ByteArrayInputStream(data.getData_value());
            try {
                OutputStream out = res.getOutputStream();
                byte[] b = new byte[in.available()];
                in.read(b);
                out.write(b);
                out.flush();
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

 

posted @ 2016-01-18 13:47  243573295  阅读(1053)  评论(0编辑  收藏  举报