有没有一个JDK类来做HTML编码(但不是URL编码)? [英] Is there a JDK class to do HTML encoding (but not URL encoding)?

查看:90
本文介绍了有没有一个JDK类来做HTML编码(但不是URL编码)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当然熟悉 java.net.URLEncoder java.net.URLDecoder 类。不过,我只需要HTML风格的编码。 (我不希望将''替换为'+'等)。我不知道在类中构建的任何JDK都只能执行HTML编码。有一个吗?我知道其他选择(例如, Jakarta Commons Lang'StringEscapeUtils',但我不想在需要此项目的项目中添加另一个外部依赖项。



我希望最近添加了一些JDK(aka 5或6),这样做我不知道,否则我必须自己推出。


<显然,答案是不。不幸的是,这是一个不得不做的事情,不能添加一个新的外部依赖性 - 在短期内,我同意每个人都认为使用Commons Lang是最好的长期解决方案,一旦我可以添加一个新的库到项目中,我就会一直这样做。



遗憾的是,这种常见用途不在Java API中。


I am of course familiar with the java.net.URLEncoder and java.net.URLDecoder classes. However, I only need HTML-style encoding. (I don't want ' ' replaced with '+', etc). I am not aware of any JDK built in class that will do just HTML encoding. Is there one? I am aware of other choices (for example, Jakarta Commons Lang 'StringEscapeUtils', but I don't want to add another external dependency to the project where I need this.

I'm hoping that something has been added to a recent JDK (aka 5 or 6) that will do this that I don't know about. Otherwise I have to roll my own.

解决方案

Apparently, the answer is, "No." This was unfortunately a case where I had to do something and couldn't add a new external dependency for it -- in the short term. I agree with everyone that using Commons Lang is the best long-term solution. This is what I will go with once I can add a new library to the project.

It's a shame that something of such common use is not in the Java API.

这篇关于有没有一个JDK类来做HTML编码(但不是URL编码)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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