我正在使用Spring MVC为404,400和500个错误实现自定义错误页面,并且我遇到了jsp页面的编码问题。
我在web.xml文件中添加了错误页面的操作:
<error-page>
<error-code>404</error-code>
<location>/404</location>
</error-page>
我创建了这个类来处理错误:
package com.axa.cfrhealth.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HTTPErrorHandler{
@RequestMapping(value="/400")
public String error400(){
System.out.println("custom error handler");
return "400";
}
@RequestMapping(value="/404")
public String error404(){
//return new ResponseEntity<Object>(null, HttpStatus.OK);
return "404";
}
@RequestMapping(value="/500")
public String error500(){
System.out.println("custom error handler");
return "500";
}
}
最后我创建了404.jsp页面:
<!-- INCLUDES -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
djhfakjhfkahakjf
</body>
</html>
但是,当我强制404错误检查自定义页面时,这是我在Chrome中遇到的错误:
ERR_CONTENT_DECODING_FAILED。
使用Fiddler检查它似乎是Chrome正在查找页面,因为从检查员我可以在TextView选项卡中看到该页面,但是无法在WebView选项卡中看到它,消息是“响应已编码并需要在启用之前解码”
这些是请求标头:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:es-ES,es;q=0.8
Cache-Control:max-age=0
Cookie:JSESSIONID=75CD658DF19B2E6DB3EB12FD354E36C3
Host:localhost:8080
http_axa_mail:albert.martinez.altran@axa-groupsolutions.com
Proxy-Connection:keep-alive
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
响应标题:
Cache-control:no-store, no-cache, must-revalidate
Cache-control:post-check=0, pre-check=0
Content-Encoding:gzip
Content-Language:en
Content-Length:429
Content-Type:text/html;charset=UTF-8
Date:Tue, 13 Oct 2015 09:15:20 GMT
Expires:Sat, 6 May 1995 12:00:00 GMT
Pragma:no-cache
Server:Apache-Coyote/1.1
似乎压缩(gzip)和charset(UTF-8)都是正确的,但即便如此,浏览器也会报告编码错误,而不是显示自定义错误页面...有人可以帮助我吗?。< / p>
问候。