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

来源:互联网 发布:soc网络安全管理平台 编辑:程序博客网 时间:2024/06/05 09:24

 

比如说   用户名为  好好学习

 

 

在传递之前使用 URLEncoder.encoder()编码后再传递

     String username = URLEncoder.encode (“好好学习”) ;

 

接收显示时

 

      String username = URLDecoder.decoder(new String(request.getParameter("username").getBytes("iso8859-1"), "utf-8"), "utf-8")

 

分开就是:

        1 通过使用指定的charsettomcat默认的是iso8859-1)解码指定的 byte 数组,构造一个新的 String

      String strBytes= request.getParameter("username").getBytes("iso8859-1") ;

 

      2 通过使用指定的 charset 解码指定的 byte 数组,构造一个新的 String

      String utfStr= new String(strBytes, "utf-8") ;

     

      3 使用指定的编码机制对字符串解码

      Strignusername = URLDecoder.decode (utfStr, "utf-8") ;

 

 

 

 

原创粉丝点击