h:outputText not rendering HTML from XML response in spite of escape=“false”

后端 未结 1 560
生来不讨喜
生来不讨喜 2020-12-10 23:40

I have the following code:


The result is:

相关标签:
1条回答
  • 2020-12-11 00:09

    It's because your text is already escaped. The escape="false" doesn't unescape text. It just prints the text as-is instead of escaping it. However, as your text is already escaped from beginning on, it appears in escaped form. Remove the escape="false" and you'll see that it will be double-escaped. I.e. every & becomes &.

    You need to unescape it beforehand. The Apache Commons Lang StringEscapeUtils may come handy.

    String unescapedShortDescription = StringEscapeUtils.unescapeXml(shortDescription);
    

    Then, you can use <h:outputText escape="false"> to print it as-is.

    0 讨论(0)
提交回复
热议问题