JSTL Function fn:escapeXml Example
- Details
- Written by Nam Ha Minh
- Last Updated on 31 August 2019   |   Print Email
This post helps you understand how to use the <fn:escapeXml> tag in the JSTL function tags library with code example.
The fn:escapeXml function escapes any markup (HTML or XML) within the string and displays the markup as plain text by rendering tags as well.
JSTL <fn:escapeXml> Syntax:
${fn:escapeXml(<markup text to escape>)}
JSTL <fn:escapeXml> Example:
The following code example displays escaped and non-escaped markup text.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>fn:escapeXml Demo</title> </head> <body> <h1>fn:escapeXml Demo</h1> <c:set var="html" value="<b><i>This is html text.</i></b>" /> <p>just html: ${html}</p> <p>html with escapeXml: ${fn:escapeXml(html)}</p> </body> </html>
Output:
Other JSTL Function Tags:
contains | containsIgnoreCase | endsWith | indexOf | join | length | replace | split | startsWith | substring | substringAfter | substringBefore | toLowercase | toUpperCase | trim
Comments