当我将我的gsp页面转换为pdf时,我收到错误

时间:2013-04-14 11:42:10

标签: grails

错误堆栈跟踪:

org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:638)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:709)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
    at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:189)
    at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:75)
    at org.xhtmlrenderer.resource.XMLResource$load.call(Unknown Source)
    at grails.plugin.rendering.document.XhtmlDocumentService.createDocument(XhtmlDocumentService.groovy:55)
    at grails.plugin.rendering.document.XhtmlDocumentService.createDocument(XhtmlDocumentService.groovy:43)
    at grails.plugin.rendering.document.XhtmlDocumentService.createDocument(XhtmlDocumentService.groovy:38)
    at grails.plugin.rendering.document.XhtmlDocumentService$createDocument.call(Unknown Source)
    at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:34)
    at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:33)
    at grails.plugin.rendering.RenderingService$render$0.callCurrent(Unknown Source)
    at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:63)
    at grails.plugin.rendering.RenderingService$render.call(Unknown Source)
    at RenderingGrailsPlugin$_closure1.doCall(RenderingGrailsPlugin.groovy:48)
    at RenderingGrailsPlugin$_closure1.call(RenderingGrailsPlugin.groovy)
    at com.zocampus.ExamScoresController$_closure31.doCall(ExamScoresController.groovy:525)
    at com.zocampus.ExamScoresController$_closure31.doCall(ExamScoresController.groovy)
    at org.grails.jaxrs.web.JaxrsFilter.doFilterInternal(JaxrsFilter.java:46)
    at java.lang.Thread.run(Thread.java:619)

1 个答案:

答案 0 :(得分:2)

<强>观察:

  • 您使用的是Grails Rendering Plugin。
  • gsp中有一个元素,其中包含'&amp;'在文中。 例如:标签为<p>S & P 500</p>

<强>解决方案: 该字符串需要编码为HTML。在gsp中使用.encodeAsHTML()您期望的'&amp;'。

示例gsp代码:

var abc = "S & P 500";
<p>abc.encodeAsHTML()</p>