tags:

views:

6490

answers:

2

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
+6  A: 

Short answer:

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

there is another option:

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

This seems overkill given the fact that we want output to be escaped 99% of the time. Is there any shorthand like <%: %> in ASP MVC 2.0?

Tae