Home » Html » How can I escape special HTML characters in JSP?

How can I escape special HTML characters in JSP?

Posted by: admin November 29, 2017 Leave a comment

Questions:

Before I go and create a custom tag or Java method to do it, what is the standard way to escape HTML characters in JSP?

I have a String object and I want to display it in the HTML so that it appears to the user as is.

For example:

String a = "Hello < World";

Would become:

Hello &lt; World
Answers:

Short answer:

<c:out value="${myString}"/>

there is another option:

<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
${fn:escapeXml(myString)}