Several solutions to the Java development of Chinese garbled characters

Source: Internet
Author: User

One: HTML garbled or the introduction of JS garbled

1: The first step, text file encoding

First make sure the file is saved in UTF-8 format, such as in Eclipse, to point attributes on the file, make sure to select UTF-8

Note that the JS file created by default in Eclispe, its encoding is GBK, note must be changed back.

2:pageencoding

Make sure that the pageencoding of the HTML file or JSP file is utf-8.

Note that the default HTML or JSP file created by Eclipse, whose pageencoding is iso-8859-1, must be changed back, as follows:

Other precautions to keep in mind

If at first forget to change pageencoding back, and then input Chinese in the file, this time will text-file-encoding to UTF-8 words, the file already exist in Chinese will become garbled.

Second: garbled characters in the process of post-transfer of web page

Suppose a Web page post is passed to the B page. First, make sure that the a page meets the above description, and secondly, on page B, the following processing is required:

Response.setcontenttype ("Text/html;charset=utf-8");
Request.setcharacterencoding ("Utf-8");
String empno = Request.getparameter ("Empno");

Third: Web page URL value process garbled

First, the URL of a Web page is encoded, similar to the following:

<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");

Several solutions to the Java development of Chinese garbled characters

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.