fn:escapeXml() JSTL Function

fn:escapeXml() JSTL Function Example explains about Escaping Special Characters In JSTL.

Consider an example where you need to escape XML markup and display exactly what we used.

fn:escapeXml() JSTL function will escape all the characters that will be interpreted as XML markup.

java.lang.String escapeXml(java.lang.String)

you can see the below example demonstrating fn:escapeXml() JSTL function 

Required Libraries

You need to download

  1. Tomcat 9
  2. JSTL 1.2

Following jar must be in classpath

  1. jstl-1.2.jar

fn:escapeXml() Example

// JSP - JSTL Escaping Special Characters

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<title>JSTL fn:escapeXml</title>

    // you can also set the values into request scope same as using c:set
    // request.setAttribute("str", ""This is a <a>test</a> String"");

<c:set var="str" value="This is a <a>test</a> String"/>
<p>Using escapeXml() Function:</p>

<p>Without Using escapeXml() Function:</p>

Using escapeXml() Function:

This is a <a>test</a> String

Without Using escapeXml() Function:

This is a test String


Your email address will not be published. Required fields are marked *