How to unescape HTML in Struts2

半腔热情 提交于 2019-12-12 03:01:32

问题


I have saved some basic HTML in a database. This HTML is via ValueStack in Action class redisplayed as <s:property value="htmlcodeString"/> in JSP file.

However, the HTML code is not interpreted, but escaped and displayed as is (eg. <b>BOLD</b> is shown instead of BOLD).

I am using Struts2. I found many recommendations on internet to use <c:out value="${text}" escapeXml="false" />. But I don't know what it is. How can I make use of it in Struts2?


回答1:


The <s:property> tag has an escapeHtml attribute which is true by default.

(Hopefully for obvious reasons.)

<c:out> is part of the JSTL, and you use it in S2 like in any other web app, with the caveat that it's because of an S2 request wrapper you can use JSP EL to access the value stack.




回答2:


I came across the question through Google and found adding the escapeHtml="false" attribute caused the JSP to stop displaying. What worked instead was simply escape="false.



来源:https://stackoverflow.com/questions/15905585/how-to-unescape-html-in-struts2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!