Is there a standard class in Java that has a method to HTML-escape a string?
< ... <
> ... >
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, there isn’t. You can use Apache Commons Lang
StringEscapeUtils#escapeHtml4for this.Update: if you have an aversion against 3rd party libraries and/or prefer homegrowing, then loop over the String’s characters and determine the character in a
switchand replace it by the escaped character. You can find here and here an example. But still, usingStringEscapeUtilsis easier on long term.