奇怪的文件编码引起的问题
我的Tomcat6.0是不是出错了哦?我新建了一个默认的MyJsp.jsp文件,文件中的代码为
<%@ page language= "java " import= "java.util.* " pageEncoding= "utf-8 "%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+ ":// "+request.getServerName()+ ": "+request.getServerPort()+path+ "/ ";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<base href= " <%=basePath%> ">
<title> My JSP 'MyJsp.jsp ' starting page </title>
<meta http-equiv= "pragma " content= "no-cache ">
<meta http-equiv= "cache-control " content= "no-cache ">
<meta http-equiv= "expires " content= "0 ">
<meta http-equiv= "keywords " content= "keyword1,keyword2,keyword3 ">
<meta http-equiv= "description " content= "This is my page ">
<!--
<link rel= "stylesheet " type= "text/css " href= "styles.css ">
-->
</head>
<body>
This is my JSP page. <br>
</body>
</html>
运行它不出错.. 大家注意MyJsp.jsps头部的pageEncoding= "utf-8 "%> 哦
可是当我运行我的另一个jsp文件,Tomcat就出错说:
/admin/admin_login.jsp(1,2) Page-encoding specified in XML prolog (UTF-8) is different from that specified in page directive (utf-8)
这意思大家都明白吧,就是说文件编码写错了一点.
我的admin_login.jsp文件的代码如下:
<%@ page language= "java " import= "java.util.* " pageEncoding= "utf-8 "%>
<%@ taglib uri= "http://jakarta.apache.org/struts/tags-bean " prefix= "bean "%>
<%@ taglib uri= "http://jakarta.apache.org/struts/tags-html " prefix= "html "%>
<html>
<head>
<title> JSP for ManagerLoginForm form </title>
</head>
<body>
<html:form action= "/managerLogin ">
用户名称 : <html:text property= "username "/> <html:errors property= "username "/> <br/>
用户密码 : <html:password property= "password "/> <html:errors property= "password "/> <br/>
<html:submit/> <html:cancel/>
</html:form> <%=request.getAttribute( "loginError ")%>
</body>
</html>
你们仔细地看一下,MyJsp.jsp和admin_login.jsp头部代码,也就是文件的第一行代码一模一样,可是我运行MyJsp.jsp就是不出错,而运行admin_login.jsp就是出错.
注:我的xml配置文件中的编码是 <?xml version= "1.0 " encoding= "UTF-8 "?>
是UTF-8,不是utf-8 &nbs