Java NLP: a complete solution to Chinese character recognition problems

Source: Internet
Author: User

Java cannot correctly display Chinese characters in the following two cases:
  
In many cases, you should determine the transcoding mode based on environment variables and debugging environment! The following methods can solve most of the problems!
  
  
1. If JDBC can properly access Chinese characters.
In the PAGE command, try contenttype = "text/htmlchaterset = gb2312"
  
Example:
<% @ Pagelanguage = "java" contentType = "text/html; charset = GB2312" import = "java. SQL. *" %>
  
2. Chinese characters cannot be properly stored in JDBC
(1) Stringaddress = request. getParameter ("address ");
Byte [] tmpbyte = address. getBytes ("ISO8859_1 ");
Address = newString (tmpbyte );
(2)
Stringname = request. getParameter ("name ");
Name = newString (name. getBytes ("gb2312"), "ISO8859_1 ");
  
"ISO8859_1" and "gb2312" can be switched

 

Example:

 

/*************************************** ***********************************
Nickname is a hypothetical field.
Temporary fields during tmnickname Transcoding
**************************************** **********************************/
  
Stringnickname = rs. getString ("nickname"). trim (); // read information ****
Byte [] tmnickname = nickname. getBytes ("ISO8859_1"); // encode and convert the information into tm ***** temporary data storage
Nickname = newString (tmnickname); // assign the converted tm *** to the field ****

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.