如何在Java中转义HTML特殊字符? [英] How to escape HTML special characters in Java?

查看:84
本文介绍了如何在Java中转义HTML特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将一个字符串转换为一个能在Web文档中正确显示的字符串?例如,更改字符串

 < Hello> 

  &安培; LT;你好&安培; gt; 中


解决方案

StringEscapeUtils 具有完全为此设计的函数:



http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/ StringEscapeUtils.html


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

"<Hello>"

To

"&lt;Hello&gt;"

解决方案

StringEscapeUtils has functions designed exactly for this:

http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/StringEscapeUtils.html

这篇关于如何在Java中转义HTML特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆