Java Chinese garbled Problem Solution

Source: Internet
Author: User

The Chinese Garbled text in Java should be a problem we often encounter. Today we will summarize the solutions to the Garbled text problem:

1. The Link contains Chinese characters. <a class = "add" href = "system/showdataadd. Action? Title = customer level & datatype = clientrank & rel = clientrankset "> Add </a>

In this way, if the data obtained in the background is not processed, Chinese characters may be garbled. Because the hyperlink actually uses the get method to transmit values, the solution to this problem is as follows:. in the conf folder of Tomcat we use

Server. XML, find <connector Port = "8080" protocol = "HTTP/1.1" connectiontimeout = "20000" redirectport = "8443"/> in the file, and add

Write uriencoding = "gb2312.

2. Use the code on the server. For example, title is a Chinese character to be processed:

public void setTitle(String title) {        try {            this.title = new String(title.getBytes("ISO-8859-1"), "gbk");        } catch (UnsupportedEncodingException e) {            e.printStackTrace();        }       }

3. The page sends the data to encodeuri once, and the server uses new string (old. getbytes ("iso8859-1"), "UTF-8 ")
For example, VAR url = "ajaxserver? Name = "+ encodeuri ($ (" # username "). Val (); // encodeuri handles Chinese garbled characters

4. encodeuri processing is performed for the data sent from the page, and urldecoder. Decode (old, "UTF-8") is used for the server ");

For example, VAR url = "users? Name = "+ encodeuri ($ (" # username "). val () + "& Password =" + encodeuri ($ ("# userpassword "). val () + "& type =" + encodeuri (input [I]. value); // encodeuri handles Chinese garbled characters

Related Article

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.