从servlet转发到错误页面(就是普通jsp,其中isErrorPage=true),转发前有一句:
request.setAttribute("javax.servlet.jsp.jspException",new NullPointerException());//其中的异常可以是任何类型,这里只是一个示意。
就会是乱码 servlet 和 jsp都是utf-8编码。如果去掉这一句,或者把javax.servlet.jsp.jspException改为别的,或者把错误页面的isErrorPage=true去掉,此问题都会消失。这是我截到的回包,发现他不会设置编码,非常奇怪:
HTTP/1.1 500 Internal Server Error
Content-Type: text/html-----------这个地方正常应该是Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 20 Jan 2006 03:54:19 GMT
Server: Apache-Coyote/1.1
Connection: close
有没有高手给个明确的解释。
request.setAttribute("javax.servlet.jsp.jspException",new NullPointerException());//其中的异常可以是任何类型,这里只是一个示意。
就会是乱码 servlet 和 jsp都是utf-8编码。如果去掉这一句,或者把javax.servlet.jsp.jspException改为别的,或者把错误页面的isErrorPage=true去掉,此问题都会消失。这是我截到的回包,发现他不会设置编码,非常奇怪:
HTTP/1.1 500 Internal Server Error
Content-Type: text/html-----------这个地方正常应该是Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 20 Jan 2006 03:54:19 GMT
Server: Apache-Coyote/1.1
Connection: close
有没有高手给个明确的解释。
<%@page import="java.util.*" %>
<html>
<head>
<title>exception</title>
</head>
<body bgcolor="#ffffff">
<h1>有错误发生</h1>
</body>
</html>-------------------------------------------
private static final String CONTENT_TYPE = "text/html; charset=UTF-8"; //Initialize global variables
public void init() throws ServletException {
} //Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE); request.setAttribute("javax.servlet.jsp.jspException",
new NullPointerException());
getServletContext().getRequestDispatcher("/exception.jsp").forward(
request, response); }
ServletException, IOException {
response.setContentType(CONTENT_TYPE); throw new NullPointerException());
}在其他的配置里配对EXCEPTION的处理页面
用了Jbuilder2005内置的tomcat4.1.30后,此故障消失。所以为认定这是tomcat的实现问题。