我需要将以下文件添加到我的 Tomcat 的“/conf”目录中:
<?xml version="1.0" encoding="UTF-8"?>
<Context useHttpOnly="false" path="/bbc">
<Realm className="com.bbc.tomcat.BBCSecurityRealm"/>
</Context>
添加此文件后,Tomcat 启动时出现以下错误"
ERROR ecmdefault util.digester.Digester 18:37:14,477 localhost-startStop-1 : Parse Fatal Error at line 1 column 1: Content is not allowed in prolog.
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1427)
最佳答案
您的 xml 文件在开头(<?xml version="1.0" encoding="UTF-8"?>
之前)有一些不可见的字符(很可能是 BOM),这在 xml 中是不允许的。您可以使用十六进制编辑器查看它。修复它的最简单方法是创建一个空文本文件并将内容复制到其中,将扩展名更改为 xml。
检查这个answer寻求进一步的帮助。
来自 http://www.rgagnon.com/javadetails/java-handle-utf8-file-with-bom.html
UTF8 file are a special case because it is not recommended to add a BOM to them because it can break other tools like Java. In fact, Java assumes the UTF8 don't have a BOM so if the BOM is present it won't be discarded and it will be seen as data.
关于java - SAX 解析异常 : Content is not allowed in prolog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20551572/