Java 编解码冒险
我尝试使用Java 编解码冒险,java,javascript,decode,encode,Java,Javascript,Decode,Encode,我尝试使用encodeURI()和encodeURIComponent()函数在javascript中对特殊字符进行编码,并使用java.net.urldecker.decode()方法对其进行解码,这在firefox中非常有效。但它在InternetExplorer中似乎不起作用。是否有其他代码可以在两种浏览器上使用相同的代码 例如: 当我传递$%^&作为值时,在编码后,它变成%24%25%5E%26。使用java.net.urldecker.decode()方法解码后,它将变成$%%5E&
encodeURI()
和encodeURIComponent()
函数在javascript中对特殊字符进行编码,并使用java.net.urldecker.decode()
方法对其进行解码,这在firefox中非常有效。但它在InternetExplorer中似乎不起作用。是否有其他代码可以在两种浏览器上使用相同的代码
例如:
当我传递$%^&
作为值时,在编码后,它变成%24%25%5E%26
。使用java.net.urldecker.decode()方法解码后,它将变成$%%5E&
这是实际值-
var str = "$%^&";
var valueJS = encodeURI(str);
var valueJS = encodeURIComponent(valueJS); // to encode even those chars in valueJS that were not encoded by encodeURI()
这是编码值-
String value = "%2524%2525%255E%2526";
while(value.matches(".*%25[A-Za-z0-9]*")) {
value = value.replace("%25", "%"); // manually trying to achieve %24%25%5E%26
}
value = java.net.URLDecoder(value, "UTF-8");
// I was expecting the decoded value to be $%^&, but it turns out to be $%%5E&
修好了。添加了2个
标签
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
使用javascript
escape()
而不是encodeURI()
和encodeURIComponent()
你说的“不工作”是什么意思?你想做什么?到底是什么不起作用?您看到了什么问题或错误消息?我无法使用您所说的上述java API进行解码,但到底是什么不起作用?您看到了哪些问题或错误消息?发生了什么?这离一个好问题越来越近了!请添加执行解码的实际Java代码行。您正在调用哪个urldecker.decode()
方法?这是不推荐的吗?