将 XML 解析器更改为 Xerces 时出现 JSP 编译错误
全部, 我正在开发一个 Java Web 应用程序,我们将其部署在 Resin Web 应用程序服务器中。我一直在对应用程序的新部分进行一些 XML 解析,并意识到我们的应用程序正在使用 Resin 类 进行解析。由于多种原因,我想摆脱这种情况并使用更标准的东西,因此我在我的resin配置文件中设置了这些系统属性(并将xerces jar添加到我的类路径中):
<system-property javax.xml.parsers.DocumentBuilderFactory="org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
<system-property javax.xml.parsers.SAXParserFactory="org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
而且,现在我遇到了JSP编译错误在几个页面上(我猜 Resin 的内置解析器更宽松)。该错误显示:
org.xml.sax.SAXParseException: The value of attribute "title" associated with an element type "display:column" must not contain the '<' character.
并且,某些页面上的“display:column”标记确实在“title”属性中包含标记。这是一个例子:
<display:column scope='col' class=" appealColorBG selectAllWidth"
title="<span class='centerThis'><label for='selectAll'>Select All</label><br />
<input type='checkbox' name='selectAll'
id='selectAll'
onClick='selectAllCheckboxes();'/></span> " >
我知道这是一些丑陋的 JSP 代码,但它也是已经投入生产的代码,所以我犹豫是否要更改它。
有谁知道我可以设置 xerces 以便它允许 JSP 按原样编译的方法吗?
All,
I'm working on a java webapp that we deploy in the Resin web app server. I have been doing some XML parsing for a new part of the application, and realized that our app was using Resin classes to do the parsing. I wanted to get away from that and use something more standard for a number of reasons, so I set these system properties in my resin config file (and added the xerces jar to my classpath):
<system-property javax.xml.parsers.DocumentBuilderFactory="org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
<system-property javax.xml.parsers.SAXParserFactory="org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
And, now I'm getting JSP compilation errors on several pages (I guess Resin's built in parser was more lenient). The error reads:
org.xml.sax.SAXParseException: The value of attribute "title" associated with an element type "display:column" must not contain the '<' character.
And, the 'display:column' tag on some pages does indeed contain markup in the 'title' attribute. Here's an example:
<display:column scope='col' class=" appealColorBG selectAllWidth"
title="<span class='centerThis'><label for='selectAll'>Select All</label><br />
<input type='checkbox' name='selectAll'
id='selectAll'
onClick='selectAllCheckboxes();'/></span> " >
That's some ugly JSP code, I know, but it's also code that's already in production, so I'm hesitant to change it.
Does anyone know of a way that I can set xerces so that it will allow the JSP to compile as is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那肯定是丑陋的 JSP 代码。
如果您在其上使用 XML 解析器,就会遇到问题。有效 XML 中的属性值不能包含“<”性格,正如 Xerces 告诉你的那样。
您能否告诉 Xerces 接受这一点值得怀疑,但是修复 XML 比让 XML 解析器接受不正确的 XML 更好。
您可能希望重新使用 Resin 类,直到您可以向 Xerces 提供正确的 XML,或者将 Resin 配置为不使用 XML 解析器作为其 JSP 编译的一部分 - 请参阅注释。
That's certainly ugly JSP code.
If you're using an XML parser on it, you've got a problem. Attribute values in valid XML can not contain the '<' character, as Xerces is telling you.
It's doubtful you can tell Xerces to accept this, but fixing the XML would be a better idea than talking an XML parser into accepting incorrect XML anyway.
You probably want to drop back to using the Resin classes until you can feed Xerces proper XML, or configure Resin to not use an XML parser as part of its JSP compilation - see comments.