Spring / Spring Interview questions II
Recommended method for escaping HTML using Java.
Using Spring's HtmlUtils.htmlEscape(String input) method.
package com.tutorials.spring; import org.springframework.web.util.HtmlUtils; public class HTMLEscape { public static void main(String[] args) { String source = "The less than sign (<) and ampersand (&) will be escaped before using it in HTML"; System.out.println(HtmlUtils.htmlEscape(source)); } }
Output: The less than sign (&lt;) and ampersand (&amp;) must be escaped before using them in HTML.
More Related questions...