java escape html string - code

1) StringEscapeUtils from Apache Commons Lang:

import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;
// ...
String source = "The less than sign (<) and ampersand (&) must be escaped before using them in HTML";
String escaped = escapeHtml(source);


OR 

2) Use Spring's HtmlUtils.htmlEscape(String input) method.

No comments :

Post a Comment

Your Comment and Question will help to make this blog better...