1  <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>

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

3 
设置web容器的编码格式
    3.1  设置servlet的doGet或doPost方法:
         request.setCharacterEncoding("utf-8");
         response.setCharacterEncoding("utf-8");
    3.2  设置tomcat容器的连接器的编码
        <Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               debug="0" connectionTimeout="20000"
               disableUploadTimeout="true" URIEncoding="utf-8" />
        还有8009端口的mod_jk的连接器的编码
            <Connector port="8009"
               enableLookups="false" redirectPort="8443" debug="0"
               protocol="AJP/1.3"  URIEncoding="utf-8"/>
   3.3 设置apache的默认字符集
         AddDefaultCharset UTF-8

database's setting
   4.0 查看database支持的字符集合
   4.1 use some character set to connect database:
    String dbUrl = "jdbc:mysql://localhost:3306/test?useUnicode=true&&characterEncoding=utf-8
";

5  compiling enviroment's configuration
   5.1   javac
   5.2   ant


save the file's content as utf-8 文件用utf-8方式另存新档
   open file with editPlus           ------->       save as      -------->   fill the file name  and  choose the charset

7
  在java代码中的设置
   servlet中:
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");   
        response.setContentType("text/html; charset=utf-8");   
   普通java代码中:
        String uniStr = new String("中文".getBytes("big5"),"utf-8");

8 相关配置文件包含中文内容
  可参考命令 native2ascii

9 设置tomcat的filter
 


http://hotforcc.javaeye.com/blog/116581
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐