在Java中用HTML实体替换字符

编程入门 行业动态 更新时间:2024-10-28 11:26:32
本文介绍了在Java中用HTML实体替换字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在某个过滤器中的HTML响应中替换其各自的HTML实体的某些字符。角色包括 ,> ,& 。我不能使用 replaceAll(),因为它将替换所有字符,甚至是HTML标签的一部分。

I want to replace certain characters with their respective HTML entities in an HTML response inside a filter. Characters include <, >, &. I can't use replaceAll() as it will replace all characters, even those that are part of HTML tags.

这样做最好的方法是什么?

What is the best approach for doing so?

推荐答案

从java可以尝试,Apache Commons Lang(legacy v2) a href =commons.apache/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html#escapeHtml(java.lang.String) = nofollow noreferrer> StringEscapeUtils.escapeHtml() 。 或与commons-lang3: StringEscapeUtils.escapeHtml4() 。

From java you may try, Apache Commons Lang (legacy v2) StringEscapeUtils.escapeHtml(). or with commons-lang3: StringEscapeUtils.escapeHtml4().

请注意,这也会转换à to & agrave; &这样的

Please note this also converts à to &agrave; & such

更多推荐

在Java中用HTML实体替换字符

本文发布于:2023-10-16 07:05:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496819.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中用   实体   字符   Java   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!