Recommended method for escaping HTML in Java

前端 未结 11 1150
南旧
南旧 2020-11-22 04:30

Is there a recommended way to escape <, >, \" and & characters when outputting HTML in plain Java code? (Other

11条回答
  •  难免孤独
    2020-11-22 04:35

    For those who use Google Guava:

    import com.google.common.html.HtmlEscapers;
    [...]
    String source = "The less than sign (<) and ampersand (&) must be escaped before using them in HTML";
    String escaped = HtmlEscapers.htmlEscaper().escape(source);
    

提交回复
热议问题