Open In App

JSTL fn:escapeXml() Function

In JSTL, the fn:escapeXml() Function is used to escape the charters that are mainly interpreted as HTML, XML, or any other tag markup. This function mainly prevents the potential security risk or rendering issues when we are displaying user-generated content in XML-based contexts. In this article, we will discuss the syntax, parameters, and example of the fn:escapeXml() function.
Syntax of fn:escapeXml() function:

${fn:escapeXml(String inputString)}

Where,



Example of JSTL fn:escapeXml() Function

In this example, we see how to find the length of a string using the JSTL fn:escapeXml() Function.




<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
    <title>JSTL Functions Example</title>
</head>
<body>
<c:set var="str1" value="Welcome to GeeksforGeeks."/>
<c:set var="str2" value="GeeksforGeeks <code>HTML</code> content."/>
<p>With escapeXml() Function:</p>
<p>String 1: ${fn:escapeXml(str1)}</p>
<p>String 2: ${fn:escapeXml(str2)}</p>
<p>Without escapeXml() Function:</p>
<p>String 1: ${str1}</p>
<p>String 2: ${str2}</p>
</body>
</html>

Output:

With escapeXml() Function:
String 1: Welcome to GeeksforGeeks.
String 2: GeeksforGeeks <code>HTML</code> content.
Without escapeXml() Function:
String 1: Welcome to GeeksforGeeks.
String 2: GeeksforGeeks content.

Output Screen of the above Program:



Explanation of the above Program:

Article Tags :