Several solutions for developing Chinese garbled characters in JAVA

Source: Internet
Author: User

Several solutions for developing Chinese garbled characters in JAVA

I. html Garbled text or JS Garbled text introduced

1: Step 1: text file encoding

First make sure that the file's save format needs to be UTF-8, such as in eclipse, to point properties on the file, make sure that the UTF-8 is selected here

Note: In eclispe, the default js file, whose encoding is gbk, must be changed back.

2: pageEncoding

Make sure that the pageEncoding of an html or jsp file is UTF-8.

Note that the default html or jsp file created by eclipse, its pageEncoding is a iso-8859-1 and must be changed back, as shown below:

Other notes

If you forget to change pageEncoding back at first, and then enter Chinese in the file, this time text-file-encoding to UTF-8, the existing Chinese in the file will become garbled.

 

Ii. garbled Characters During the POST process

Assume that the POST value of webpage A is sent to webpage B. First, make sure that webpage A meets the description described in the previous section. Second, on Webpage B, perform the following operations:

 

response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
String empno = request.getParameter("empno");

 

3. garbled Characters During webpage URL value transfer

First, encode the URL of webpage A, such:

 

<A href = "delete. jsp? Ename = <% = java.net. URLEncoder. encode (rs. getObject ("ename"). toString (), "UTF-8") %> "> Delete </a>

Then, on page B, you need:

 

String msg = request.getParameter("ename");
String ename=new String(msg.getBytes("ISO-8859-1"),"UTF-8");

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.