![](/img/trans.png)
[英]How to recursively Print data from template data Map Object in Freemarker?
[英]How to escape '&' in data coming from webservice in freemarker template?
Freemarker:
如果我的数据是:
x = [{
name= satyajit,
company = hewlett & packard
}, {
name= akanksha,
company = google & co
}]
以下是我如何访问ftl模板中的以上列表。
${x}
但是,以上代码引发错误:实体名称必须紧跟在实体引用中的“&”之后。
是否有一种方法可以从freemarker模板中的Web服务数据中转义数据中的“&”,例如“ hewlett&packard”中的“&”?
编辑:
遇到错误:
[Fatal Error] NewFile.xml:27:57: The entity name must immediately follow the '&' in the entity reference.
Exception in thread "main" org.xml.sax.SAXParseException; systemId: file:/D:/NewFile.xml; lineNumber: 27; columnNumber: 57; The entity name must immediately follow the '&' in the entity reference.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
将<#escape x中的文本块包装为x?html>指令。
public static final String ESCAPE_PREFIX = "<#ftl strip_whitespace=true><#escape x as x?html>";
public static final String ESCAPE_SUFFIX = "</#escape>";
ESCAPE_PREFIX + templateText + ESCAPE_SUFFIX
请参阅: http : //freemarker.org/docs/dgui_misc_autoescaping.html
http://watchitlater.com/blog/2011/10/default-html-escape-using-freemarker/
搜索了一段时间后,我发现内置的freemarker html可以解决我的情况。 就我而言:
${x?html}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.