Coding garbled problem in Java Web

Source: Internet
Author: User

b/S mode in a Java Web project, both front and back end. During the process of development, during debugging, the running process often encounters garbled problems. Then from the phenomenon, analyze the problem:

  

1, the Project Guide in, the page comments and other non-Western languages are garbled. First look at the workspace encoding, now my GBK encoding. Then look at the encoding for this page.

Check the page properties selected in the IDE tool to see. Such as:. This means that the code in my file is now encoded in a utf-8 way. If you change this code to another encoding here. Then there will be garbled characters. For example, after I changed this program to Iso-8859-1, I found that all non-western characters in the page became garbled. So found in a file of non-Western European text is garbled at the beginning, you can view her encoding properties. UE and other tools can be viewed. Look at the same code as your main workspace. There is a high probability that this conversion will be garbled in eclipse. It is recommended to do it in a programmer such as UE.

2, the parameters of the page when the request is sent. The front end passes the query parameters to the backend, and the backend returns the parameters after the data is queried by the parameters. The scenario is that the front-end requests the arguments in a get way. The GET request front end must be encoded with Urlencoder.encode () when transmitting non-Western text, and then transmitted.

The server should be decoded in the same way as the new String (Request parameter. GetBytes ("Iso-8859-1"), "GBK"). If you do not add Urlencoder.encode (), different browsers have different font encoding methods.

Coding garbled problem in Java Web

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.