首页 > 技术文章 > encoding specified in XML prolog (UTF-8) is different from that specified in page directive (utf-8)

wangshunyao 2017-10-25 13:35 原文

myeclipse下启动项目后出现错误:encoding specified in XML prolog (UTF-8) is different from that specified in page directive (utf-8)  

org.apache.jasper.JasperException: /WEB-INF/jsp/xx.jsp(1,2) Page-encoding specified in XML prolog (UTF-8) is different from that specified in page directive (utf-8)  
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)  

原因分析:这种错误是因为编码不一致导致,可能项目编码是UTF-8,而JSP页面用其他工具打开,比如记事本,导致编码从UTF-8 变成UTF-8-BOM,所以出现该问题。低版本的tomcat不能解析这个编码

解决办法:

  第一种:将JSP中的 pageencoding改为与WEB INF下的web.xml的pageencoding一样就好;

  第二种:升级tomcat,tomcat6+ 都可以解析

推荐阅读