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