1、对要进行URL传递的中文字符进行编码:
String message = java.net.URLEncoder.encode("中文字符","utf-8");
2、在取URL传递中文的页面对字符进行解码:
String msg = request.getParameter("message");
String str=new String(msg.getBytes("ISO-8859-1"),"UTF-8");
--------------------------------------------------------------------------------------
注 1、这里得出的str就是先前传入的"中文字符"。
2、为什么要对取出的字符集形式转换成UTF-8形式,是因为ISO-8859-1是Java中网络传输使用的标准字符集,request.getParameter("message");得到的还是ISO-8859-1字符集,所以要转换一下。
URLDecoder和URLEncoder它的作用主要是用于普通字符串和application/x-www-form-rulencodedMIME字符串之间的转换,