The fn:escapeXml() function
The fn:escapeXml() function ignores characters used for XML markup.
Syntax
The syntax of the fn:escapeXml() function is as follows:
${fn:escapeXml(<要转义标记的文本>)}
Example Demonstration
The following example demonstrates the function:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
Using JSTL Functions
使用 escapeXml() 函数:
string (1) : ${fn:escapeXml(string1)}
string (2) : ${fn:escapeXml(string2)}
不使用 escapeXml() 函数:
string (1) : ${string1}
string (2) : ${string2}
The running result is as follows:
Using the escapeXml() function:
string (1) : This is first String.
string (2) : This is second String.
Without using the escapeXml() function:
string (1) : This is first String.
string (2) : This is second String.
JSP Standard Tag Library