【功能】:从本地的磁盘读取图片显示在jsp界面

Controller层:

    @RequestMapping("/showPdf")
    public void showPdf(HttpServletResponse response) throws IOException {
        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("application/pdf;charset=UTF-8");
        FileInputStream input = new FileInputStream(new File("C:\\Users\\smart-003\\Downloads\\test.pdf"));
        byte buffBytes[] = new byte[1024];
        OutputStream out = response.getOutputStream();
        int read = 0;
        while ((read = input.read(buffBytes)) != -1) {
            out.write(buffBytes, 0, read);
        }
        out.flush();
        out.close();
    }
@RequestMapping("/ccc")
    public void ccc(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String url="";
        Map<String,Object> map = (Map<String, Object>) request.getSession().getAttribute("inputMessImage");
        System.out.println(map.get(1));
        String dir=map.get("iamgedir").toString();
        String name=map.get("imagename").toString();
        url=dir+'/'+name;
        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("application/pdf;charset=UTF-8");
        FileInputStream inp = new FileInputStream(new File(url));
        byte buffBytes[] = new byte[1024];
        OutputStream outputStream = response.getOutputStream();
        int read =0;
        while ((read = inp.read(buffBytes))!=-1)
        {
            outputStream.write(buffBytes,0,read);
        }
        outputStream.flush();
        outputStream.close();
    }

JSP页面:

<div style="width:55%;float:left;height: 550px;margin-right:2%;margin-left:1.5%;" >
<iframe align="center" height="550px" width="100%" src="/ccc"  frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div>
<div style="width:40%;float:left;height: 45%">
<iframe align="center"  height="550px" id="dealIframe" name="dealIframe" width="100%" src="<%=((Map)request.getSession().getAttribute("inputMessImage")).get("formzuurl")%>"  frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="yes" ></iframe>
</div>
发布了91 篇原创文章 · 获赞 14 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/Abenazhan/article/details/98052741