【问题标题】:render html using jstl with html tags intact使用 html 标签完整的 jstl 渲染 html
【发布时间】:2015-04-03 18:39:34
【问题描述】:

我正在尝试渲染这个字符串:

"<p>bold: <i>test</i> food <b>journal</b> entry</p>"

像这样使用 jstl:

1) <c:out value="${topic.text}" escapeXml="true"/>
2) <c:out value="${topic.text}" escapeXml="false"/> 
3) ${topic.text}

这些都没有按预期工作。我希望文本显示为 html。但是结果是(在浏览器上打印的):

1) <p>bold: <i>test</i> food <b>journal</b> entry</p>

2) bold: test food journal entry

3) bold: test food journal entry

我怎样才能得到: 测试食物 期刊条目

【问题讨论】:

  • 没关系,我找到了问题和解决方案。

标签: html css jsp jstl spring-el


【解决方案1】:

您拥有的最后一个${topic.text} 将完全按原样输出原始字符串,而不会转义,如果该字符串不起作用,则该字符串可能不是您认为的那样。是否有可能修改字符串,例如 getText getter?

【讨论】:

  • 是的,你是对的。实际上,我删除了输入字符串中的

    标签,现在一切正常。可能是

    在 css 中定义了一些样式,这导致了这种情况。

【解决方案2】:

使用这个。

 <c:set var="str" value="<p>bold: <i>test</i> food <b>journal</b> entry</p>" />
    <c:set var="str1">${str}</c:set>
    ${str1}

【讨论】:

    猜你喜欢
    • 2011-09-17
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    • 2017-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多