1

我有一个这样的网址:

localhost:8080/demo?xml=hello"<xyz>&#xa";

在这里我想解码<> 


4

4 回答 4

2

来自 apache Common -StringEscapeUtils#escapeHtml()可以简化你的工作。

String string= StringEscapeUtils.unescapeHtml(encodedString);
于 2013-09-03T10:04:30.077 回答
1

首先提取要解码的部分:

 String str = url.substring(str.indexOf('"') + 1, str.lastIndexOf('"'));

然后使用StringEscapeUtils.unescapeHtml4对其进行解码:

 String result = StringEscapeUtils.unescapeHtml4(str);
于 2013-09-03T10:04:01.687 回答
1

我假设您能够提取 URL 中引号之间的字符串。然后你可以使用Apache Commons Lang ( StringEscapeUtils.unescapeHtml4 ) 来取消转义特殊实体:

String unescapedString = StringEscapeUtils.unescapeHtml4("<xyz>&#xa");
于 2013-09-03T10:04:22.263 回答
1

Apache Commons Lang 提供的使用方法

import org.apache.commons.lang.StringEscapeUtils;
// ...
String afterDecoding = StringEscapeUtils.unescapeHtml(beforeDecoding);
于 2013-09-03T10:06:22.700 回答