中文乱码有关问题的解决方案

中文乱码问题的解决方案

在WebService调用中,经常会发生中文乱码问题,除了服务器的配置(如tomcat的server.xml中设置encodeURI=“utf-8”)外,还有一些影响中文乱码的因素。

1.  在web page中设置

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 当然,设置的位置在head。

2.  如果使用js,可以使用js的encodeURI编码

data:{id:id,name:encodeURI(name)}

 在程序中再使用Decoder.decode来解码

String name = URIDecoder.decoder(name);

3.  使用jquery时,如果是post方法,使用cotent-type

contentType:"application/x-www-form-urlencoded; charset=utf-8"

     get方法则在程序中使用

String dist = new String(source.getBytes("ISO-8859-1"), "UTF-8");