How to stop html textarea from interpreting html entities into their characters

后端 未结 1 1161
情书的邮戳
情书的邮戳 2020-12-22 10:14

I have an html textarea that is used to display a string from a database. The textarea can be edited and any changes are saved to the database.

The problem is that w

相关标签:
1条回答
  • 2020-12-22 10:31

    So you want to escape HTML entities? You can use either JSTL <c:out> or fn:escapeXml().

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    ...
    <textarea><c:out value="${bean.text}" /></textarea>
    

    or

    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    ...
    <textarea>${fn:escapeXml(bean.text)}</textarea>
    

    It will by default escape under each & to &amp; so that for example &reg; ends up to become &amp;reg; and this way it will be displayed as &reg;.

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