java - SAX 解析异常 : Content is not allowed in prolog

标签 java tomcat sax

我需要将以下文件添加到我的 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/

相关文章:

java - 单个应用程序有两个 list 文件?

java - 为多个域的 Apache Tomcat 部署 WAR 文件

android - SAX、StringBuilder 和内存泄漏

Java SAX 解析器引发 UnknownHostException

java - SAXBuilder jdom 给出异常

java - 如何在spring data jpa中映射好友请求实体

java - 如何使用java反转缓冲区内的字节

java - 为什么 Integer 类缓存值在 -128 到 127 范围内?

java - org.apache.tomcat.dbcp.dbcp.SQLNestedException : Cannot get a connection, 池错误等待空闲对象超时

java - apache tomcat中的子域实时映射