记-网页上某些图片用 火狐 、谷歌、360极速模式等都可以正常显示。但是用 ie、360兼容模式 却不能正常显示。浏览器报DOM7009: 无法解码 URL 处的图像

一、问题描述

网页上某些图片用 火狐 、谷歌、360极速模式等都可以正常显示。但是用 ie、360兼容模式 却不能正常显示。浏览器报DOM7009: 无法解码 URL 处的图像。

二、原因

ContentType内容格式不正确,例如将image/png,写成image/jpeg。

@RequestMapping("/captcha.do")
    public void getCaptcha(HttpServletRequest request, HttpServletResponse response) {
        // 设置相应类型,告诉浏览器输出的内容为图片
        response.setContentType("image/jpeg");
        // 不缓存此内容
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expire", 0);
        ServletOutputStream out = null;
        try {
			# Hutool工具包生成验证码(输出图片为png格式)
            AbstractCaptcha captcha = CaptchaUtil.createLineCaptcha(200, 100);
            captcha.setBackground(new Color(15, 70, 140, 255));
            HttpSession session = request.getSession();
            session.removeAttribute(KEY_CAPTCHA);
            session.setAttribute(KEY_CAPTCHA, captcha.getCode());
            out = response.getOutputStream();
            captcha.write(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

三、解决办法

response.setContentType(“image/png”);

@RequestMapping("/captcha.do")
    public void getCaptcha(HttpServletRequest request, HttpServletResponse response) {
        // 设置相应类型,告诉浏览器输出的内容为图片
        response.setContentType("image/png");
        // 不缓存此内容
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expire", 0);
        ServletOutputStream out = null;
        try {
			# Hutool工具包生成验证码(输出图片为png格式)
            AbstractCaptcha captcha = CaptchaUtil.createLineCaptcha(200, 100);
            captcha.setBackground(new Color(15, 70, 140, 255));
            HttpSession session = request.getSession();
            session.removeAttribute(KEY_CAPTCHA);
            session.setAttribute(KEY_CAPTCHA, captcha.getCode());
            out = response.getOutputStream();
            captcha.write(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

搬山境KL攻城狮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值