JSTL fn:escapeXml() function

The JSTL fn:escapeXml() function is used to escape the html, xml or any other tag which can be treated as xml markup.
Syntax: String escapeXml(String giventring)

Example:

test.jsp
<%@ 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>fn:escapeXml JSTL function example</title>
 </head>
 <body>
  <c:set var="testString" 
                 value="

Hello this is a JSTL function example

"
/> <h4>String without using escapeXml function.</h4> ${testString}<br/> <h4>String with using escapeXml function.</h4> ${fn:escapeXml(testString)} </body> </html>
web.xml
<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list> 
 
</web-app>

Output:


No comments: