---
title: "java 乱码问题解决九步曲"
author: "mapengfei00099"
date: "2011-04-17T09:05:11Z"
tags: ["JDBC", "Java", "MySQL", "SQL", "脚本"]
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2011-04-17T09:05:11Z"
id: 1005411
url: "https://mapengfei00099.iteye.com/blog/1005411"
---

一、数据库

1.创建数据库时启动mysql使用参数  
mysql -uroot -p  --default-character-set utf8  
2.创建数据库  
create database summer(库名) default character set utf8; 执行sql脚本

3.创建表  
        create table emp(表名)(列表.....)default character set utf8;  
4.sql脚本的执行  
        source /home/tarena/phone.sql(sql脚本)

5.修改mysql 数据库连接url  
jdbc:mysql://localhost:3306/summer(库名)?useUnicode=true&characterEncoding=utf8  
二、页面

6.提交时使用post提交

 &lt;form action="xxx.do" method="post"&gt;  
7.jsp页面设置字符集  
 &lt;[%@page](mailto:%@page) pageEncoding="utf-8" contentType="text/html;charset=utf-8" %&gt;

三、处理器

8.使用过滤器filter  
        request.setCharacterEncoding("utf-8");  
 response.setCharacterEncoding("utf-8");  
   
9.在地址栏传中文的问题  
        服务器端将传输过来的中文进行进行下面的解码：  
              String name=new String(request.getParameter("name").getBytes("ISO8859-1"),"utf-8");