Jboss Seam, mysql Chinese garbled Problem 4 steps Summary

Source: Internet
Author: User
In fact, the following summary is applicable to any situation of hibernate + mysql;

Step 1: Specify the encoding when creating a database Schema, such as mysql. Use the following statement to create a Schema:

SQL code

Create schema xxxx default character set utf8;

This step is required because at least I have not found the hbm2ddl configuration method on the Internet so that the encoding of the database table generated by hibernate can be specified, setting a default encoding for the schema is the easiest way. Of course, you can also not set the default encoding for the schema. After hibernate generates a table, you can change the encoding in one table. For more information, see the Database Help documentation.

If "Step 1" is not confirmed, the following steps can be ignored;

Step 2: Set meta information on every page of the project

Html code

<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>

This is not much to explain. After this is set, at least your page can accommodate Chinese characters. In this step, we recommend that you use the template technology to add this meta to the template at the outermost layer. You do not need to add this meta to every page.

At this point, you will find that it is okay to directly write the Chinese characters on the page. It is no problem to directly use the console of the database management client to insert Chinese characters, that is, there is a problem with the Chinese data inserted through the program; so:

Step 3: Specify the database connection url parameters, for example:

Xml Code

Jdbc: mysql: // localhost: 3306/data115? UseUnicode = true & amp; characterEncoding = UTF-8

In this way, the data inserted through the program can also be done.

Finally, sometimes you need to GET in the url parameters to pass Chinese, the url in the Chinese is to be encoded before the transfer, such as tomcat default uriEncoding is iso-8859-1, this will cause garbled characters in the Chinese values passed through the url. configure "URIEncoding = 'utf-8'" in the connector node of xml, for example:

Xml Code

<Connector port = "8080" address = "$ {jboss. bind. address }"
MaxThreads = "250" maxHttpHeaderSize = "8192"
EmptySessionPath = "true" protocol = "HTTP/1.1"
EnableLookups = "false" redirectPort = "8443" acceptCount = "100"
ConnectionTimeout = "20000" disableUploadTimeout = "true" URIEncoding = 'utf-8'/>

I am jboss, server. xml location in deploy/jboss-web.deployer, tomcat is very good to find, the configuration is the same.

Finally, do you think there is another method of "filter? The filter was useful when struts was used for a while before, but now I have tested it in seam and found that there is no relation to this filter. I just need to confirm that the above 4 steps should be garbled; I guess if the Framework Program does not use hard encoding to encode using a non-UTF-8 character set, no filter is needed.

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.