zoukankan      html  css  js  c++  java
  • img标签中src引用绝对的路径报错:Not allowed to load local resource: file:///D://data/upload/banner.png

    浏览器直接访问file:///D://data/upload/banner.png是可以的,但在页面里就是不显示

    解决:不配置绝对路径,src里访问后台,参数为图片名称,通过应用服务器获取图片输出

    jsp:

    后台:

     @RequestMapping("/image/{filename}")
     public void showImageByType(@PathVariable String filename, HttpServletRequest request, HttpServletResponse response) throws Exception {
            InputStream inputStream = null;
            OutputStream writer = null;
            try {
                String root = ReadeGlobePa.getValueByProper("fileSaveDir");
                filename = filename.replace("/", "");
                filename = filename.replace("..", "");
                inputStream = new FileInputStream(new File(root + "/upload/" + filename));
                writer = response.getOutputStream();
    
                byte[] buf = new byte[1024];
                int len = 0;
                while ((len = inputStream.read(buf)) != -1) {
                    writer.write(buf, 0, len); //
                }
                inputStream.close();
            } catch (FileNotFoundException e) {
                response.setStatus(404);
            } catch (Exception e) {
    //            logger.error(e.getMessage(), e);
            } finally {
                try {
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    if (writer != null) {
                        writer.close();
                    }
                } catch (IOException e) {
                    logger.error(e.getMessage(), e);
                }
            }
        }
  • 相关阅读:
    eclipse版本、代号
    eclipse中jdk及编译器版本问题
    改变cmd命令行颜色
    mysql-installer-community-8.0.12.0的安装
    算法简介
    Java--将数据以文本形式导出
    安装MySQL
    网络配置
    电脑拷软件到其他设备
    探针设备
  • 原文地址:https://www.cnblogs.com/wjq-/p/14950111.html
Copyright © 2011-2022 走看看