Java平台字符编码问题


在项目实施中,我们非常有必要对整个工程项目中的字符编码问题进行统一。

具体的实施方案如下:


1、Jsp和Servlet文件中的字符编码原理与设置:(文件和浏览器字符编码)

 1     /*设置Jsp页面……
 2      *指定将Jsp文件解析成java文件时的字符编码格式
 3      **/
 4     <% pageEncoding="UTF-8" %>    
 5 
 6     /*指定对服务器响应进行重新编码的字符编码格式
 7      **/
 8     <% ContentType="text/html; charset=UTF-8"%>
 9 
10     /*指定浏览器采用的字符编码格式
11      **/
12     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
13     
14     /*设置对客户端请求进行重新编码的字符编码格式
15      **/
16     request.setCharacterEncoding("UTF-8");
17     
18     /*指定对服务器响应进行重新编码的字符编码格式
19      **/
20     response.setCharacterEncoding("UTF-8");    
21 
22     /*设置连接数据库的字符编码形式
23      **/
24     /*在Jsp或Servlet文件中*/
25     jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8
26     /*在xml文件中*/
27     jdbc:mysql://localhost:3306/databaseName?useUnicode=true&amp;characterEncoding=UTF-8

浏览器端字符编码
服务器端字符编码

2、MySQL数据库中的字符编码原理与设置:(数据库字符编码)

 1     # ----------------------------------------------------------------------
 2     #
 3     # The following options will be read by MySQL client applications.
 4     # Note that only client applications shipped by MySQL are guaranteed
 5     # to read this section. If you want your own MySQL client program to
 6     # honor these values, you need to specify it as an option during the
 7     # MySQL client library initialization.
 8     #
 9     [client]
10 
11     port=3306
12 
13     [mysql]
14 
15     default-character-set=latin1/*设置为你想要使用的字符编码形式*/
16 
17 
18     # SERVER SECTION
19     # ----------------------------------------------------------------------
20     #
21     # The following options will be read by the MySQL Server. Make sure that
22     # you have installed the server correctly (see above) so it reads this 
23     # file.
24     #
25     [mysqld]
26 
27     # The TCP/IP Port the MySQL Server will listen on
28     port=3306
29 
30 
31     #Path to installation directory. All paths are usually resolved relative to this.
32     basedir="C:/Program Files/MySQL/MySQL Server 5.1/"
33 
34     #Path to the database root
35     datadir="C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.1/Data/"
36 
37     # The default character set that will be used when a new schema or table is
38     # created and no character set is defined
39     default-character-set=latin1/*设置为你想要使用的字符编码形式*/

3、WEB服务器中字符编码原理及设置:(应用服务器的字符编码)

1     /*设置URI的字符编码形式
2      **/
3     Tomcat6.0的conf文件夹下server.xml中
4         <Connector executor="tomcatThreadPool"
5                port="8080" protocol="HTTP/1.1" 
6                connectionTimeout="20000" 
7                redirectPort="8443" URIEncoding="UTF-8"/>

4、JVM的字符编码格式
Java的class文件采用utf8的编码方式,JVM运行时采用Unicode(utf16)

5、开发平台中数据流的加载处理流程及原理:
……

转载于:https://www.cnblogs.com/ljmatlight/archive/2012/11/25/2787883.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值