Vm中一个超链接URL需要拼接中文作为Get请求的参数。如果直接拼接,传到后台Action的参数对象中后取出会是乱码,需要编码后再拼接到URL上。
:调用java.net.URLEncoder的encode()方法时,如果没有显示指定字符集参数,那么URLEncoder会使用默认字符集。这个默认字符集在Eclipse里跑m
/**
* Translates a string into <code>x-www-form-url
encoded</code>
* format. This method uses the platform'sdefault encoding
* as the encoding scheme to o
BTain thebytes for unsafe characters.
*
* @par
am s <code>String</code> to betranslated.
* @de
PRecated The resulting string may
VARy de
PEnding on the platform's
* default encoding. Instead, use theencode(String,String)
* method to specify the encoding.
* @return the translated <code>String</code>.
*/
@Deprecated
p
ublic
static String encode(String s) {
String str = null;
try {
str = encode(s,
DFltEncName);
} catch(UnsupportedEncodingException e) {
// The
System should always have theplatform default
}
return str;
}