Form form Forms common garbled problem solution

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Form forms are an important part of the Web site program, but Formolu forms often appear garbled, causing a lot of trouble for the site. For form forms common garbled problem, here I summed up a number of solutions, hoping to help everyone.

1, the form submits the garbled question

In the form of submission, often in the submission of Chinese will appear some garbled, which is also a common form of garbled. Forms can be submitted in two ways: Get and post submissions. So there is a GET request and a POST request on request. Then the two kinds of requests generated by the garbled problem, the solution is different. If I do a form submission for lottery software development, the data that is passed to the server when using GET Requests is appended to the URL address, and the data that is passed to the server when the post is requested is passed to the server as part of the request body. This leads to a different way of handling the garbled characters they produce.

(1) The client's GET request

For the client's GET request, server-side processing to avoid garbled, solve this problem slightly more complex, need to use the string type of constructor, one of the constructors is to use the specified encoding to decode, generally using the "UTF-8" way. Simply reconstruct the requested parameter to a string on the server side. After construction, the client enters Chinese and, in the case of a GET request in the form, Str becomes Chinese.

(2) Client POST request

For the client post request, the problem of handling garbled is simpler because the requested data is passed to the server as part of the request, so just modify the code within the request. Just set the requested data to "UTF-8" at the very beginning of the server side, and enter the following statement: request. Setcharacterencoding ("UTF-8") so that the user in the server-side to get the Chinese data is no longer garbled.

2, the hyperlink appears garbled

In web development, a lot of times are through hyperlinks to pass Chinese parameters, this will also result in the display of garbled, for the hyperlink, it is actually sent to the server side of a request, and it sent a request belongs to get request, so for the hyperlink garbled, It handles garbled ways and forms of get requests appear garbled way is the same.

3, the browser version of the low resulting garbled

This problem is also very common, different browsers, different versions will appear some garbled problems. such as in a lottery software development www.88856856.cn site to submit some information, the address bar shows the word "%2c%c6%cc%c6", in fact, this is to prevent the emergence of garbled solution, if your browser is IE6 or the following version, Then our second and third cases will be garbled (especially when the Chinese is odd), which is not good so we have to adopt a more practical approach:

The Urlencoder class and Urldcoder classes are provided in the java.net package, which provides encode and decode two static methods, respectively, for encoding and decoding. We will be passing the Chinese parameters to encode, after passing to the server, the server decoded, you can display Chinese.

Code: Urlencoder.encode (Stuname, "UTF-8")

Pass to server: "> Delivery

Decoding: Urldecoder.decode (Stuname, "UTF-8")

Form forms of the emergence of garbled problem there are many, here is only in my work in the common garbled problem. In fact, you will find in the work, the form of the garbled problem is still very much, hope that experienced friends can share some experience.

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.