Use:

StringEscapeUtils.escapeHtml("I'm coder")

Escapes the characters in a String using HTML entities.

For example:

"bread" & "butter"

Becomes:

"bread" & "butter".

Answer from Srikanth Puliroju on Stack Overflow
🌐
Apache Commons
commons.apache.org › proper › commons-text › javadocs › api-release › org › apache › commons › text › StringEscapeUtils.html
StringEscapeUtils (Apache Commons Text 1.9 API)
Translator object for escaping HTML version 3.0. While escapeHtml3(String) is the expected method of use, this object allows the HTML escaping functionality to be used as the foundation for a custom translator.
🌐
GitHub
github.com › apache › commons-lang › blob › master › src › main › java › org › apache › commons › lang3 › StringEscapeUtils.java
commons-lang/src/main/java/org/apache/commons/lang3/StringEscapeUtils.java at master · apache/commons-lang
* {@code StringEscapeUtils.ESCAPE_XML.with( NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE));}</p> * * @param input the {@link String} to escape, may be null · * @return a new escaped {@link String}, {@code null} if null string input · * @see #unescapeXml(String) * @deprecated Use {@link #escapeXml10(java.lang.String)} or {@link #escapeXml11(java.lang.String)} instead.
Author   apache
🌐
Baeldung
baeldung.com › home › java › java string › escape html symbols in java
Escape HTML Symbols in Java | Baeldung
January 8, 2024 - Let’s explore multiple approaches to escape HTML symbols in Java: Apache Commons Text library provides a reliable utility class, StringEscapeUtils, that offers the escapeHtml4() method for escaping HTML symbols:
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-2.6 › org › apache › commons › lang › StringEscapeUtils.html
StringEscapeUtils (Commons Lang 2.6 API)
January 10, 2011 - Escapes and unescapes Strings for Java, Java Script, HTML, XML, and SQL. ... Apache Software Foundation, Apache Jakarta Turbine, Purple Technology, Alexander Day Chaffee, Antony Riley, Helge Tesgaard, Sean Brown, Gary Gregory, Phil Steitz, Pete Gieser ... StringEscapeUtils instances should NOT be constructed in standard programming.
🌐
How to do in Java
howtodoinjava.com › home › string › java escape html – encode special characters
Java Escape HTML - Encode Special Characters
October 10, 2023 - Java examples to escape HTML using the StringEscapeUtils.escapeHtml4(), Spring's HtmlUtils.htmlEscape() and custom logic for special cases.
🌐
Tabnine
tabnine.com › home page › code › java › org.apache.commons.lang.stringescapeutils
org.apache.commons.lang.StringEscapeUtils.escapeHtml java code examples | Tabnine
/** * Escape HTML content. i.e. replace characters with &values; * * @param content * content * @return escaped content */ public static String escapeHtml( String content ) { if ( Utils.isEmpty( content ) ) { return content; } return StringEscapeUtils.escapeHtml( content ); }
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › tagged › stringescapeutils
Newest 'stringescapeutils' Questions - Stack Overflow
java · spring-boot · xss · checkmarx · stringescapeutils · DujSn28 · 13 asked Sep 24, 2021 at 6:33 · 0 votes · 0 answers · 2k views · With the goal to prevent html code injection and cross-site scripting, there is a filter built for service requests to escape some characters using: StringEscapeUtils.escapeHtml(text) However, this is ...
🌐
Mkyong
mkyong.com › home › java › how to escape html in java
How to escape HTML in Java - Mkyong.com
January 20, 2020 - In Java, we can use Apache commons-text, StringEscapeUtils.escapeHtml4(str) to escape HTML characters.
🌐
GitHub
github.com › apache › commons-text › blob › master › src › main › java › org › apache › commons › text › StringEscapeUtils.java
commons-text/src/main/java/org/apache/commons/text/StringEscapeUtils.java at master · apache/commons-text
* Escapes and unescapes {@code String}s for Java, Java Script, HTML and XML. * </p> * * <p> * #ThreadSafe# * </p> * * <p> * This code has been adapted from Apache Commons Lang 3.5. * </p> * * @since 1.0 · */ public class StringEscapeUtils { · /* ESCAPE TRANSLATORS */ ·
Author   apache
🌐
Java Tips
javatips.net › api › org.apache.commons.lang.stringescapeutils
Java Examples for org.apache.commons.lang.StringEscapeUtils
/** * 转义字符. * * @param string 字符 * @param type 字符类型 */ public static String escape(String string, String type) { String unescape = "�支�对" + type + "字符的转义"; if (type.equals(LanguageUtils.CONST_HTML)) { unescape = StringEscapeUtils.escapeHtml(string); } else if (type.equals(LanguageUtils.CONST_XML)) { unescape = StringEscapeUtils.escapeXml(string); } else if (type.equals(LanguageUtils.CONST_SQL)) { unescape = StringEscapeUtils.escapeSql(string); } else if (type.equals(LanguageUtils.CONST_JAVA)) { unescape = StringEscapeUtils.escapeJava(string); } else if (type.equals(LanguageUtils.CONST_JavaScript)) { unescape = StringEscapeUtils.escapeJavaScript(string); } else if (type.equals(LanguageUtils.CONST_CSV)) { unescape = StringEscapeUtils.escapeCsv(string); } return unescape; }
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-release › org › apache › commons › lang3 › StringEscapeUtils.html
StringEscapeUtils (Apache Commons Lang 3.11 API)
Translator object for escaping HTML version 3.0. While escapeHtml3(String) is the expected method of use, this object allows the HTML escaping functionality to be used as the foundation for a custom translator.
🌐
Codingwithharish
codingwithharish.com › posts › java-stringescapeutils-guide
Complete StringEscapeutils Guide in Java | Coding with Harish
September 3, 2023 - StringEscapeUtils.escapeJava is used for escaping strings intended to be used as values in Java properties files.
🌐
Apache Commons
commons.apache.org › proper › commons-text › apidocs › org › apache › commons › text › StringEscapeUtils.html
StringEscapeUtils (Apache Commons Text 1.15.1-SNAPSHOT API)
... Returns a String value for a CSV column enclosed in double quotes, if required. ... Escapes the characters in a String using EcmaScript String rules. ... Escapes the characters in a String using HTML entities. ... Escapes the characters in a String using HTML entities. ... Escapes the ...
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-3.1 › org › apache › commons › lang3 › StringEscapeUtils.html
StringEscapeUtils (Commons Lang 3.1 API) - Apache Commons
July 19, 2011 - Translator object for escaping HTML version 4.0. While escapeHtml4(String) is the expected method of use, this object allows the HTML escaping functionality to be used as the foundation for a custom translator. ... Translator object for escaping individual Comma Separated Values.