我有一个这样的网址:
localhost:8080/demo?xml=hello"<xyz>
";
在这里我想解码<
和>


来自 apache Common -StringEscapeUtils#escapeHtml()
可以简化你的工作。
String string= StringEscapeUtils.unescapeHtml(encodedString);
首先提取要解码的部分:
String str = url.substring(str.indexOf('"') + 1, str.lastIndexOf('"'));
然后使用StringEscapeUtils.unescapeHtml4对其进行解码:
String result = StringEscapeUtils.unescapeHtml4(str);
我假设您能够提取 URL 中引号之间的字符串。然后你可以使用Apache Commons Lang ( StringEscapeUtils.unescapeHtml4 ) 来取消转义特殊实体:
String unescapedString = StringEscapeUtils.unescapeHtml4("<xyz>
");
Apache Commons Lang 提供的使用方法
import org.apache.commons.lang.StringEscapeUtils;
// ...
String afterDecoding = StringEscapeUtils.unescapeHtml(beforeDecoding);