现在的位置: 首页 > 综合 > 正文

页面之间传递和接收显示中文参数

2014年01月26日 ⁄ 综合 ⁄ 共 547字 ⁄ 字号 评论关闭

 

比如说
  

用户名为
 

好好学习

 

 

在传递之前使用
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"
) ;

 

 

 

 

抱歉!评论已关闭.