Question mark (Chinese) is displayed after ubuntu is deployed in java.

Source: Internet
Author: User

Question mark (Chinese) is displayed after ubuntu is deployed in java.

1. First, remember the encoding format of your project, that is, the encoding format used for local encoding. UTF-8
2. Check tomcat settings in web. xml and server:
Server. xml:

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" /><Connector port="8009" protocol="AJP/1.3" redirectPort="8443"  URIEncoding="UTF-8"/>

Remove comments from the following content in web. xml:

<filter>        <filter-name>setCharacterEncodingFilter</filter-name>        <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>        <init-param>            <param-name>encoding</param-name>            <param-value>UTF-8</param-value>        </init-param>        <async-supported>true</async-supported>    </filter>

3. Check the encoding format on the ubuntu server.

// Check the local language environment: locale // modify the configuration vi/etc/profile // Add the following lines (LC_ALL indicates all settings, but does not affect LANG ): export LANG = "en_US.UTF-8" export LC_ALL = "zh_CN.UTF-8" // enable it after setting source/etc/profile // when a cannot error occurs, run the following command to install the appropriate language pack sudo locale-gen zn_CN.UTF-8 // when it becomes effective, to enter the configuration again to modify, delete the added two lines, otherwise it will affect the jdk Environment

4. mysql Configuration
1. Modify the default mysql Configuration:
Default mysql configuration: the server and client are all latin1, which is not supported for Chinese characters. Here it is changed to utf8
Method:
Modify the configuration file:

Vim/etc/mysql/my. cnf

[Mysqld]
Character-set-server = utf8
Collation-server = utf8_general_ci

Restart mysql

/Etc/init. d/mysql restart

Check the encoding method:

Mysql> show variables like 'Char % ';
+ -------------------------- + ---------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------- +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | latin1 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | utf8 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +
2. Modify the database configuration used by the Project
Change the database encoding method to utf8 (default value: latin1)
Mysql> alter database name character set utf8;

View the database encoding:
Mysql> status

Connection id: 41
Current database: tslcrms
Current user: root @ localhost
SSL: Not in use
Current pager: stdout
Using outfile :''
Using delimiter :;
Server version: 5.5.38-0ubuntu0. 14.04.1 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket:/var/run/mysqld. sock
Uptime: 53 min 14 sec

Mysql> show create database tslcrms;
+ ---------- + ------------------------------------------------------------------ +
| Database | Create Database |
+ ---------- + ------------------------------------------------------------------ +
| Tslcrms | CREATE DATABASEDatabase Name/*! 40100 default character set utf8 */|
+ ---------- + ------------------------------------------------------------------ +

3. The encoding methods of the tables and fields in the imported database files are modified to utf8.
You can directly change the. SQL file and import it.
You can also import it first, and then use commands to view and change it.

Appendix: use commands in mysql to modify character sets:
Mysql> SET character_set_client = utf8;

 mysql> SET character_set_connection = utf8 ; mysql> SET character_set_database = utf8 ; mysql> SET character_set_results = utf8 ; mysql> SET character_set_server = utf8 ; mysql> SET collation_connection = utf8 ; mysql> SET collation_database = utf8 ; mysql> SET collation_server = utf8 ;

Set names 'utf8 ';
It is equivalent to the following three commands:
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;

5. In addition
The default Character Set of mysql is latin1, so it should be changed to utf8. Many articles on the Internet run "sudo vi/etc/mysql/my. cnf". But when you open it, there are two lines in it:

!includedir /etc/mysql/conf.d/!includedir /etc/mysql/mysql.conf.d/

I think the mysql configuration file should be under the two folders, so I tried to open/etc/mysql. conf. d/mysqld. run the following command in the cnf file:

~ $ Sudo vi/etc/mysql. conf. d/mysqld. cnf

[Client]
Default-character-set = utf8

[Mysqld_safe]
Socket =/var/run/mysqld. sock
Nice = 0

[Mysqld]
Character-set-server = utf8
Collation-server = utf8_general_ci

Then restart the Mysql server.
~ $ Sudo/etc/init. d/mysql restart
~ $ Mysql-u root-p
Mysql> show variables like "% char %"
+ -------------------------- + ---------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------- +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | utf8 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | utf8 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +


Join the study exchange group 569772982 to learn and exchange.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.