HTML Encoder/Decoder for Java
Free online html encoder/decoder with Java code examples
Working with html encoder/decoder in Java? Our free online html encoder/decoder helps Java developers format, validate, and process data instantly. Below you will find Java code examples using Apache Commons Text so you can achieve the same result programmatically in your own projects.
Try the HTML Encoder/Decoder Online
Use our free HTML Encoder/Decoder directly in your browser — no setup required.
Open HTML Encoder/DecoderJava Code Example
import org.apache.commons.text.StringEscapeUtils;
String raw = "<script>alert(\"XSS\")</script>";
String encoded = StringEscapeUtils.escapeHtml4(raw);
System.out.println(encoded);
String decoded = StringEscapeUtils.unescapeHtml4(encoded);
System.out.println(decoded);Quick Setup
Library: Apache Commons Text
<!-- Maven: org.apache.commons:commons-text:1.12.0 -->Java Tips & Best Practices
- StringEscapeUtils handles HTML4 entity encoding/decoding
- Use escapeXml11 for XML-safe encoding
- Spring Framework has HtmlUtils.htmlEscape() as well