Chinese garbled characters in Flash + blazeds + spring + MySql

Source: Internet
Author: User

In this environment, the problem of Chinese garbled characters is solved. From the front-end to the database, it is best to use a unified utf8 encoding. Not all links listed here need to be set. You can check them step by step. If there are garbled characters in the database, try it first. If there is a problem with Flex display, see 3 and 4.

I. MySQL garbled characters

If the Chinese characters in the database are garbled, check the MySQL settings first.

1. Create a table using the utf8 character set:

Create Table 'table '(

'Id' int (11) not null auto_increment,

.....

'Createtime' timestamp not null default current_timestamp on update current_timestamp,

Primary Key ('id ')

) Engine = InnoDBDefault charset = utf8;

2. Set the default character set for my. ini:

Character-set-Server = utf8

Default-character-set = utf8

You can use show variables like 'character % '; To view variable values related to MySQL character encoding.

Ii. Spring defines datasource

This refers to the connection URL of datasource defined in bean. Datasource is set at (/WEB-INF/spring/infrastructure-config.xml)

<Bean id = "mysqlds" class = "org. springframework. JDBC. datasource. drivermanagerdatasource">
<Property name = "driverclassname" value = "com. MySQL. JDBC. Driver"/>
<Property name = "url" value = "JDBC: mysql: // localhost: 3306/web2test? Useunicode = true & amp; characterencoding = utf8 "/>
<Property name = "username" value = "root"/>
<Property name = "password" value = "admin123456"/>
</Bean>

 

Iii. file encoding

Both Java and flex projects use utf8 in the code file format.

Set text file encoding to UTF-8 in project> Properties> resource.

 

Iv. Flash end, Set flash. system. system. usecodepage = true;

"Flash. system. system. usecodepage: it determines which code page to use to interpret external text files. When this attribute is setfalseThe external text file is interpreted as Unicode. (UNICODE must be used to encode these files .) When this attribute is set
trueThe traditional code page of the operating system that runs the application is used to interpret external text files.useCodePageThe default value is
false."

 

V. Tomcat settings

/Tomcat/CONF/server. xml

<Connector Port = "8400" protocol = "HTTP/1.1" connectiontimeout = "20000"
Uriencoding = "UTF-8"
Redirectport = "9400" type = "regxph" text = "yourobjectname"/>

 

6. Java end

Add an encoding and conversion filter to Web. xml.

<Filter>

<Filter-Name> character encoding filter </filter-Name>

<Filter-class> edu. lltang. characterencodingfilter </filter-class>

<Init-param>

<Param-Name> encoding </param-Name>

<Param-value> UTF-8 </param-value>

</Init-param>

</Filter>

<Filter-mapping>

<Filter-Name> character encoding filter </filter-Name>

<URL-pattern>/* </url-pattern>

</Filter-mapping>

 

Edu. lltang. characterencodingfilter. Java

Public class characterencodingfilter implements filter {

Private filterconfig = NULL;

Public void destroy (){}

@ Override

Public void dofilter (servletrequest arg0, servletresponse arg1, filterchain arg2) throws ioexception, servletexception {

Arg0.setcharacterencoding (filterconfig. getinitparameter ("encoding "));

Arg2.dofilter (arg0, arg1 );

}

@ Override

Public void Init (filterconfig arg0) throws servletexception {

This. filterconfig = arg0;

}

}

 

VII. xml

If XML is used for data exchange, remember to display the specified encoding in XML. <? XML version = "1.0" encoding = "UTF-8"?>

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.