本文介绍了如何在 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 &lt; 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)}

这篇关于如何在 JSP 中转义特殊的 HTML 字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:36
查看更多