Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我去创建自定义标记或 Java 方法之前,在 JSP 中转义 HTML 字符的标准方法是什么?
我有一个 String 对象,我想在 HTML 中显示它,以便它按原样显示给用户。
例如:
String a = "Hello < World";
会成为:
Hello < World
简短的回答:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <c:out value="${myString}"/>
还有另一种选择:
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> ${fn:escapeXml(myString)}