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();
            }
        }
    }
原文地址:https://www.cnblogs.com/hwaggLee/p/5139017.html