How to escape HTML special characters in Java?

后端 未结 5 1632
名媛妹妹
名媛妹妹 2021-01-01 21:01

Is there a way to convert a string to a string that will display properly in a web document? For example, changing the string

\"\"
5条回答
  •  庸人自扰
    2021-01-01 21:46

    That's usually called "HTML escaping". I'm not aware of anything in the standard libraries for doing this (though you can approximate it by using XML escaping). There are lots of third-party libraries that can do this, however. StringEscapeUtils from org.apache.commons.lang has a escapeHtml method that can do this.

提交回复
热议问题