Java转义HTML [英] Java escape HTML

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

问题描述

目前我使用 org.apache.commons.lang.StringEscapeUtils escapeHtml()来转义我的字符串中的不需要的HTML标签,但后来我意识到它转义了带有重音符号的字符& something;,也是,我不想要。

currently I use org.apache.commons.lang.StringEscapeUtils escapeHtml() to escape unwanted HTML tags in my Strings but then I realized it escapes characters with accents to &something;, too, which I don't want.

你知道任何解决方案来转义HTML标签但是请留意我的特别(好吧,对于一些人来说,他们在这里是正常的)信件?

Do you know any solution for escaping HTML tags but leave my special (well, for some people, they are normal here ;]) letters as they are?

提前感谢!

balázs

推荐答案

StringUtils.replaceEach(str, new String[]{"&", "\"", "<", ">"}, new String[]{"&amp;", "&quot;", "&lt;", "&gt;"})

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

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