【功能】:从本地的磁盘读取图片显示在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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值