It converts special characters to HTML entities, preventing execution.
HTML encoding transforms characters like '' into '<' and '>', making it difficult for injected scripts to execute. For example, if a user inputs '', encoding it will render it as plain text rather than executable code, neutralizing potential XSS attacks in a Java web application.
Additional Notes
Why is HTML encoding essential for preventing XSS?