Use UTF-8 for tomcat + mysql

Source: Internet
Author: User

Using UTF-8 is actually the preferred choice for jsp (SUN Enterprise applications)
Therefore, web pages often require the input or output of multilingual languages.
It is a convenient code.
In fact, it is not difficult to set the transcoding settings of jsp (the preferred choice for SUN Enterprise Applications). Just remember to add them.
Otherwise, the encoding defined in jsp (the first choice for SUN Enterprise Applications) is not a UTF-8.

It is a pity that MySQL (the best combination with PHP) has not yet fully supported UTF-8
But don't be discouraged.
Because I can access UTF-8 coding data through the JDBC interface of Connection/J provided by MySQL (the best combination with PHP)
Using JDBC automatic transcoding is very convenient for those who write webpages.

Haola !! Not to mention... enter the topic now
I will explain it in the following steps. Very few, but they all need to be set.
I just proposed it for your attention.

1. Connect to MySQL through JDBC (the best combination with PHP)
12
Class. forName ("com. mySQL (the best combination with PHP ). jdbc. driver "). newInstance (); Connection conn = DriverManager. getConnection ("jdbc: MySQL (the best combination with PHP): // [hostname]/[database]? User=& password = & useUnicode = true & characterEncoding = UTF-8 ");
 
The red letter must be added.
Because that's a call (call should be okay) JDBC uses the UTF-8 code to access data
Simply put
Is jsp (SUN Enterprise Application preferred) with JDBC said ...... I only need UTF-8. Other free talk ....
So let's get to know ^"

PS:
In fact, I suggest using jsp (the first choice for SUN Enterprise Applications) include methods at least. comparison will not cause errors.
You only need to include the file when necessary. If you have any problems, you only need to find an archive.
Don't check whether there are any errors like I have to check every one of them...
The problem is that the JDBC encoding of an archive is set to Big5.
It took me many days to find it .....
More advanced friends, but it would be easier to Use JavaBean for control.

2.
The page must be set to the following code:
1
<% @ Page contentType = "text/html; charset = UTF-8" %>
 

Is with jsp (SUN Enterprise Application preferred) with browsers (such as IE) said my encoding to use UTF-8 to display

The following pageEncoding can be added without adding... I am used to adding
I don't know if there will be any problems
Please refer to the javamon65 large precision article will learn more about http://www.javaworld.com.tw/jute/post/view? Bid = 6 & id = 27113 & sty = 2
1
<% @ Page pageEncoding = "UTF-8" %>
 


3.
When you use Form to pass data to another webpage
The encoding mode for receiving data must also be set.
Otherwise, the encoding of the received data is defined in jsp (preferred for SUN Enterprise applications ).
All you see is garbled.
1
<% Request. setCharacterEncoding ("UTF-8"); %>
 


4.
On the contrary, if you pass the information out (the form seems to be included too. I am not sure about this)
You must set the following code.
1
<% Response. setContentType ("text/html; charset = UTF-8"); %>
 

Tell tomcat (a very useful JSP operating platform) to use UTF-8 to process data transfer

5.
This is also very important.
Remember to edit your jsp file (preferred for SUN Enterprise applications)
Remember to save as UTF-8 format when storing
Because I use Dreamweaver MX
MX will automatically store your files based on ContentType, so don't worry.
But if you use NotePad (NotePad) to write jsp (the preferred choice for SUN Enterprise applications ),
It is necessary to select the UTF-8 format to store the license on the file format side
Otherwise, garbled characters are displayed on the webpage.
Ex: You save it in Big5 format for archiving. But the webpage code is set to UTF-8
That jsp (SUN Enterprise Application preferred) with the browser contact is naturally to handle UTF-8
So the Big5 format will be converted into a UTF-8... Of course it is garbled
So remember this very important thing.

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.