IE11和Spring Boot(1.3.3)有一个奇怪的问题。 当为IE11激活兼容模式时,错误页面无法正确显示。而是在浏览器中显示下载窗口。
以下是重现错误的方法:
Spring Tool Suite:
Internet Explorer 11:
现在打开“localhost:8080”时,浏览器不再显示Spring Whitelabel错误。它要求您从“localhost”下载“8080”。真是胡说八道: - (
我认为问题与此错误有关:https://github.com/spring-projects/spring-boot/issues/3633 但在这里,用户至少得到一个默认的IE 404错误。
不幸的是我必须使用兼容模式,因为“在兼容性视图中显示Intranet站点”是我们公司的浏览器默认值... 有谁知道如何解决这个问题?
PS:我也尝试在自定义错误页面中设置<meta http-equiv="X-UA-Compatible" content="IE=9; IE=EDGE; text/html; charset=UTF-8" />
,但也没有帮助。
答案 0 :(得分:0)
IE通过HTTP请求标头字段发送不同的Accept: Content-Types
值列表,而不是例如Chrome确实如此。我无法重现您描述的奇怪的下载行为,但是使用不同的浏览器我也得到了针对同一请求的不同响应。
使用IE我收到Content-Type: application/json
响应
使用Chrome时,它是一个Content-Type: text/html
响应。
您必须告诉服务器您的whitelabel错误页面应生成Content-Type
。这可以通过覆盖Spring Boot的默认ErrorController
来完成:
@Controller
public class YourCustomController implements ErrorController{
private static final String PATH = "/error";
@RequestMapping(value = PATH, produces={"text/html"})
public String error() {
return "error";
}
@Override
public String getErrorPath() {
return PATH;
}
}
这应该可以解决问题。一个新的错误控制器,它生成Content-Type: text/html
而不是错误的Content-Type
,这可能会迫使您的浏览器进行下载。
根据您使用的模板引擎(如果您完全使用MVC方法),请注意application properties appendix of the spring boot documentation中描述的配置参数spring.<your engine>.content-type
。