JSTL Functions - escapeXml()
The fn:escapeXml() function escapes characters that can be interpreted as XML markup.
Syntax:
The fn:escapeXml() function has following syntax:
java.lang.String escapeXml(java.lang.String)
JSTL Example :
<%@ 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 Tutorial</title> </head> <body> <c:set var="str1" value="India is my country"/> <c:set var="str2" value="<alpha>India</alpha> is my country"/> <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 : India is my country string 2 :India is my country Without escapeXml() Function: string 1 : India is my country string 2 : India is my country