亂碼解決九步曲

來源:互聯網
上載者:User

一、資料庫

1.建立資料庫時啟動mysql使用參數
 mysql -uroot  --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提交
 <form action="xxx.do" method="post">

7.jsp版面設定字元集
 <%@page pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>

三、處理器

8.使用過濾器filter
        request.setCharacterEncoding("utf-8");
 response.setCharacterEncoding("utf-8");
 
9.在地址欄傳中文的問題
        伺服器端將傳輸過來的中文進行進行下面的解碼:
              String name=new String(request.getParameter("name").getBytes("ISO8859-1"),"utf-8");

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.