zoukankan      html  css  js  c++  java
  • 关于IE中图片不显示的问题(IE兼容问题)

    修改前在IE里是这样。。或者更惨都是小黑x。。我就纳闷了,在别的浏览器都好使。。

     找了好久原因 。。

     最终发现是 response.setContentType 设置的问题。

     之前我是这样写的:

    response.setContentType("image/*");

    后来就改成 发现 png 不显示

    response.setContentType("image/jpeg");

    然后在网上找了一个比较全的图片 ContentType

    最终是这样的

       private static Map<String, String> imageContentType = new HashMap<>();
        static {
            imageContentType.put("jpg", "image/jpeg");
            imageContentType.put("jpeg", "image/jpeg");
            imageContentType.put("png", "image/png");
            imageContentType.put("tif", "image/tiff");
            imageContentType.put("tiff", "image/tiff");
            imageContentType.put("ico", "image/x-icon");
            imageContentType.put("bmp", "image/bmp");
            imageContentType.put("gif", "image/gif");
        }
        
        public static final String showImg(HttpServletResponse response, String path) throws IOException {
              // 获取文件名后缀
              String fileType = path.substring(path.lastIndexOf(".") + 1).toLowerCase();
              FileInputStream fileIs=null;
              try {
                  fileIs = new FileInputStream(path);
              } catch (Exception e) {
               return null;
              }
              int i=fileIs.available(); //得到文件大小   
              byte data[]=new byte[i];   
              fileIs.read(data);  //读数据
              response.setContentType(imageContentType.get(fileType));
              //response.setContentType("image/jpeg"); //设置返回的文件类型   图片
              OutputStream outStream=response.getOutputStream(); //得到向客户端输出二进制数据的对象
              outStream.write(data);  //输出数据
              outStream.flush();
              outStream.close();   
              fileIs.close();
              return path;
        }

    @

  • 相关阅读:
    试图运行项目时出错,无法启动调试。没有正确安装调试器(转帖)
    IIS 401.2
    windows 2008 r2 64位运行crystal 2008的问题
    .net 命令行
    crystal report 2008 公式字段问题
    vs2003在IE8下无法调试的解决办法 (包括win2008 64位)
    Oninit里不能用ViewState
    web 开发的一些软件
    silverlight toolkit
    SqlConnection.Open的一些问题
  • 原文地址:https://www.cnblogs.com/DarGi2019/p/13366921.html
Copyright © 2011-2022 走看看