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;
        }

    @

  • 相关阅读:
    网友对角摩客户端的一些建议
    利用hha.dll生成chm格式电子书
    博客园memcached专题手机电子书
    角摩手机电子书生成器JoymoBookwww.joymo.cn
    角摩网的在线电子书制作专家也完成了(http://online.joymo.cn)
    typedef 及其与struct的结合使用
    《图像理解理论与方法》(3)
    引用、return
    《图像理解理论与方法》(1)
    《图像理解理论与方法》(2)
  • 原文地址:https://www.cnblogs.com/DarGi2019/p/13366921.html
Copyright © 2011-2022 走看看