[英]Thymeleaf and inline scripts SAXParseException
I got a page which uses thymeleaf template, and I'm getting the following error on page load when using inline scripts: 我有一个使用百里叶模板的页面,在使用内联脚本时,我在页面加载时遇到以下错误:
org.xml.sax.SAXParseException;
org.xml.sax.SAXParseException; lineNumber: 270;
lineNumber:270; columnNumber: 85;
columnNumber:85; The content of elements must consist of well-formed character data or markup.
元素的内容必须由格式良好的字符数据或标记组成。
Code at line 270 第270行的代码
<script type="text/javascript" >
window.jQuery || document.write("<script src='assets/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
</script>
I have tried replacing "<", ">" symbols from document.write with <
我试过用
<
document.write替换“<”,“>”符号<
>
, the exception doesn't occur anymore but the script is not loaded anymore ,不再发生异常,但不再加载脚本
You need to add CDATA tags for the script like this: 您需要为脚本添加CDATA标记,如下所示:
<script type="text/javascript">
//<![CDATA[
window.jQuery || document.write("<script src='assets/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
//]]>
</script>
The tags are telling thymeleaf's xml parser that the code between should not be interpreted as XML markup. 标签告诉thymeleaf的xml解析器,它们之间的代码不应该被解释为XML标记。
This is no longer necessary since Thymeleaf 3.0 自Thymeleaf 3.0以来不再需要这样做了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.