Reputation: 6087
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' product.
What's wrong? And how can I fixed it? Thanks.
Upvotes: 2
Views: 25096
Reputation: 31
Use:
StringEscapeUtils.escapeHtml("I'm coder")
Escapes the characters in a String using HTML entities.
For example:
"bread" & "butter"
Becomes:
"bread" & "butter".
Upvotes: 3
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