比如说 用户名为 “ 好好学习 ”
在传递之前使用 URLEncoder.encoder() 编码后再传递
String username = URLEncoder.encode (“ 好好学习 ”) ;
接收显示时
String username = URLDecoder.decoder( new String( request.getParameter("username").getBytes("iso8859-1") , "utf-8" ) , "utf-8" )
分开就是:
1
通过使用指定的
charset
(
tomcat
默认的是
iso8859-1
)解码指定的
byte
数组,构造一个新的
String
String strBytes = request.getParameter( "username" ).getBytes( "iso8859-1" ) ;
2
通过使用指定的
charset
解码指定的
byte
数组,构造一个新的
String
String utfStr = new String(strBytes, "utf-8" ) ;
3 使用指定的编码机制对字符串解码
Strign username = URLDecoder.decode (utfStr, "utf-8" ) ;
本文介绍了如何使用URLEncoder.encode()进行编码以及URLDecoder.decode()进行解码的具体步骤,并提供了从客户端到服务器端处理中文参数的完整流程。
196

被折叠的 条评论
为什么被折叠?



