How can I escape special HTML characters in JSP?

最后都变了- 提交于 2019-12-27 12:05:31

问题


Before I go and create a custom tag or Java method to do it, what is the standard way to escape HTML characters in JSP?

I have a String object and I want to display it in the HTML so that it appears to the user as is.

For example:

String a = "Hello < World";

Would become:

Hello &lt; World

回答1:


Short answer:

<c:out value="${myString}"/>

there is another option:

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


来源:https://stackoverflow.com/questions/475839/how-can-i-escape-special-html-characters-in-jsp

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