Chen Li Yong
Chen Li Yong

Reputation: 6087

StringEscapeUtils.escapeHtml

I'm working in JSP, and I'm still fairly new at this. I need to change single aposthropy into ' or ', and double aposthropy into " or " using StringEscapeUtils.escapeHtml. It compiled successfully. But it didn't work.

Here's my exact testing code.

<%= StringEscapeUtils.escapeHtml("cool 4' product") %>

In view page source, the result is:

cool 4' product

not

cool 4&#39; product.

What's wrong? And how can I fixed it? Thanks.

Upvotes: 2

Views: 25096

Answers (2)

Srikanth Puliroju
Srikanth Puliroju

Reputation: 31

Use:

StringEscapeUtils.escapeHtml("I'm coder")

Escapes the characters in a String using HTML entities.

For example:

"bread" & "butter"

Becomes:

&quot;bread&quot; &amp; &quot;butter&quot;.

Upvotes: 3

Endre
Endre

Reputation: 50

to quote the StringEscapeUtils.escapeHtml javadocs, as in https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html#escapeHtml%28java.lang.String%29

Supports all known HTML 4.0 entities, including funky accents. Note that the commonly used apostrophe escape character (') is not a legal entity and so is not supported).

So you have to do that manually.

Upvotes: 0

Related Questions