如何在JSP中避免特殊的HTML字符? [英] How can I escape special HTML characters in JSP?
本文介绍了如何在JSP中避免特殊的HTML字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我去之前,创建一个自定义标签或Java方法来做,在JSP中转义HTML字符的标准方法是什么?
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?
我有一个String对象而且我想在HTML中显示它,以便它看起来像用户一样。
I have a String object and I want to display it in the HTML so that it appears to the user as is.
例如:
String a = "Hello < World";
将成为:
Hello < World
推荐答案
简答:
<c:out value="${myString}"/>
还有另一个选项:
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
${fn:escapeXml(myString)}
这篇关于如何在JSP中避免特殊的HTML字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文