Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape HTML special characters in Java?

Tags:

java

html

Is there a way to convert a string to a string that will display properly in a web document? For example, changing the string

"<Hello>"

To

"&lt;Hello&gt;"
like image 565
Nathaniel Flath Avatar asked Aug 03 '09 22:08

Nathaniel Flath


1 Answers

StringEscapeUtils has functions designed exactly for this:

http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/StringEscapeUtils.html

like image 120
Amber Avatar answered Oct 01 '22 01:10

Amber