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);
                }
            }
        }
  • 相关阅读:
    CENTOS安装部署zabbix
    分解XML方法
    Git使用摘要
    POJ 1274 The Perfect Stall 水二分匹配
    [leetcode]Pascal's Triangle II
    swift学习笔记(六)析关闭过程和使用分配给属性的默认值
    Qt学习一门:直接使用QT具
    mybatis13 resultMap
    mybatis12 Usermapper.xml
    mybatis11 sqlMapConfig.xml文件说明
  • 原文地址:https://www.cnblogs.com/wjq-/p/14950111.html
Copyright © 2011-2022 走看看