直接访问errorpage.jsp不是乱码,但是通过web-xml跳转之后,就显示成???????了,为什么呢ErrorPagr.jsp如下
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page isErrorPage="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>错误提示</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<body onload="tishi();">
<%
response.setStatus(200); // 200 = HttpServletResponse.SC_OK
%>
<center><h3>原因可能有:数据库连接错误,网络断开或者长时间没有操作导致连接丢失等等。</h3></center>
</body>
</html>web.xml 如下:
<?xml version="1.0" encoding="UTF-8"?>
<error-page>
<error-code>500</error-code>
<location>/system/errorPage.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/system/errorPage.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/system/errorPage.jsp</location>
</error-page>
<error-page>
<exception-type>java.sql.SQLException</exception-type>
<location>/system/errorPage.jsp</location>
</error-page>
</web-app>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page isErrorPage="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>错误提示</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<body onload="tishi();">
<%
response.setStatus(200); // 200 = HttpServletResponse.SC_OK
%>
<center><h3>原因可能有:数据库连接错误,网络断开或者长时间没有操作导致连接丢失等等。</h3></center>
</body>
</html>web.xml 如下:
<?xml version="1.0" encoding="UTF-8"?>
<error-page>
<error-code>500</error-code>
<location>/system/errorPage.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/system/errorPage.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/system/errorPage.jsp</location>
</error-page>
<error-page>
<exception-type>java.sql.SQLException</exception-type>
<location>/system/errorPage.jsp</location>
</error-page>
</web-app>
嗯,楼上的说的没错。
在web.xml 配置好编码方式吧。
在servlet里面已经设了UTF-8了
还有一点就是,在MyEclipse里面运行,怎么都没错,但是我把class直接拷到Tomca Webapps里面运行,就会出现乱码