The display of the database is garbled

Source: Internet
Author: User

In mysql4.1.0, the varchar type, the text type will appear in Chinese garbled, for the varchar type to set it as a binary property
Can solve the Chinese problem, for the text type is to use an encoding conversion class to handle, the implementation is as follows:
 

    Public classConvert {/**convert the Iso-8859-1 code into GB2312*/     Public Staticstring ISOTOGB (String iso) {string GB; Try{if(Iso.equals ("") | | ISO = =NULL) {return""; }Else{ISO=Iso.trim (); GB=NewString (Iso.getbytes ("iso-8859-1"), "GB2312"); returnGB; }}Catch(Exception e) {System.err.print ("Encoding Conversion error:" +e.getmessage ()); return""; }}}

By compiling it into class, you can call the static method Isotogb () of the Convert class to convert the encoding.
  
Summarize:
1. <%@ page contenttype= "text/html in JSP; Charset=a "%> if specified, all constructs in the JSP are modified
String (not a reference), and if no encoding is specified, then the encoding of these strings is a.
The string obtained from the request is iso-8859-1 if no code for the request is specified.
The string obtained from the other place is using the original encoding, such as getting a string from the database, if the database is encoded
is B, then the string encoding is b instead of a, and it is not the system default.
At this point, if the string to be output is not a, then, it is likely to show garbled, so the first to correctly convert the string
The string to encode a, and then output.
2. <%@ page contenttype= "text/html in JSP; Charset=a "%> is not specified, then the equivalent is specified <%@
Page contenttype= "text/html; Charset=iso-8859-1 "%>
3. Servelte If a response.setcontenttype ("Text/html;charset=a") is executed, the description will response the
Character output stream encoding is set to a, all the string to be output to the encoding to be converted to a, otherwise it will get garbled.
The string encoded in Servelet from request is the same as in the JSP, but is constructed in the servlet Java file.
String is the default encoding used by the system. The string obtained from the outside of the Servelt is encoded using the original, such as from the
The data obtained from a database of code B is encoded as B, not a, and not the default encoding of the system.


Previously written, migrated to this

Original link: http://user.qzone.qq.com/372806800/blog/1336199097

The display of the database is garbled

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.