zoukankan      html  css  js  c++  java
  • springMVC读取本地图片显示到前端页面

        @RequestMapping("/getImage")
        @ResponseBody
        public void getImagesId(HttpServletResponse rp) {
            String filePath = "G:\1.jpg";
            File imageFile = new File(filePath);
            if (imageFile.exists()) {
                FileInputStream fis = null;
                OutputStream os = null;
                try {
                    fis = new FileInputStream(imageFile);
                    os = rp.getOutputStream();
                    int count = 0;
                    byte[] buffer = new byte[1024 * 8];
                    while ((count = fis.read(buffer)) != -1) {
                        os.write(buffer, 0, count);
                        os.flush();
                    }
    
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        fis.close();
                        os.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
    
            }
        }

    方法一:在浏览器输入请求地址,就可以看到本地的图片

    方法二:在jsp中使用<img src=“请求地址” />,也可以看到本地的图片

  • 相关阅读:
    Mac 键盘快捷键
    行业分析
    大数据导航
    SQL循环语句 详解
    SQL中使用循环结构
    常用 git 基础命令
    最近众包-有意思
    薪酬体系设计
    海氏评估法
    原则类
  • 原文地址:https://www.cnblogs.com/jiefu/p/10900579.html
Copyright © 2011-2022 走看看