BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

fn:escapeXml() – JSTL Function

Last Updated: December 1, 2013 by Chaitanya Singh | Filed Under: JSTL

fn:escapeXml() JSTL function is used for HTML/XML character escaping which means it treats html/xml tags as a string rather than markup tags. It is similar to the escapeXml attribute of <c:out> tag. Let’s understand this with the help of an example-

Syntax

String escapeXml(String input_string)

Converts the input_string into a output string after escaping html/xml markup tags.

  • function return type is String
  • Argument: input String

fn:escapeXml() Example

Here we have two Strings which have html tags bold(<b>) and italic (<i>). We are processing them using fn:escapeXml() function.

<%@ 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 fn:escapeXml() example</title>
</head>
<body>
Message1: <b>Hi This is just a message</b>
<br>Message2: <i>This is an example</i>
<br>Message1 and fn:escapeXml(): ${fn:escapeXml("<b>Hi This is just a message</b>")}
<br>Message2 and fn:escapeXml(): ${fn:escapeXml("<i>This is an example</i>")}
</body>
</html>

Output:

As you can see when we used the function on input strings, the html tags didn’t work and get printed as it is, just like another normal string.

fn-escapeXml-example

Top Related Articles:

  1. fn:join() and fn:split() JSTL Functions
  2. fn:substring(), fn:substringAfter() & fn:substringBefore() Functions
  3. fn:toUpperCase() – JSTL Function
  4. JSTL <c:redirect> Core Tag
  5. JSTL <c:out> Core Tag

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Comments

  1. Prateek Ashtikar says

    June 5, 2014 at 7:50 PM

    Hello,

    Many Thanks for example. But I would like to escape all html characters and prints only values in it
    For Example:
    If passing TestUser —> I should get value only TestUser
    If passing TestUATUser –> I should get value TestUATUser

    Could any one please suggest what function or code I need to used? Your input is much appreciated.

    regards,

    Reply

Leave a Reply Cancel reply

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

JSTL Core Tags

  • c:out
  • c:set
  • c:remove
  • c:if
  • c:choose
  • c:when
  • c:otherwise
  • c:catch
  • c:import
  • c:forEach
  • c:forTokens
  • c:param
  • c:url
  • c:redirect
JSTL Functions
  • fn:contains()
  • fn:containsIgnoreCase()
  • fn:indexOf()
  • fn:escapeXML()
  • fn:join() & fn:split()
  • fn:length()
  • fn:startsWith()
  • fn:endsWith()
  • fn:substring()
  • fn:substringAfter()
  • fn:substringBefore()
  • fn:trim()
  • fn:toUpperCase()
  • fn:toLowerCase()
  • fn:replace()

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap