When java accepts get requests sent from the android client, garbled code is used to solve the problem.

Source: Internet
Author: User

When java accepts get requests sent from the android client, garbled code is used to solve the problem.

This afternoon, I encountered a very common problem. However, after N times, I couldn't find an effective solution, A simple and effective method is developed.The implementation idea is as follows::

(1) Before the android client sends a get requestString str = URLEncode. encode (str, "UTF-8 ");Specify the encoding format as UTF-8 so that android clients send requests to the server in UTF-8 format.

(2) The server obtains the parameter value through request. getParameter ("str. In this way, the obtained parameter values will not be garbled!

Note:(1) str indicates the variable name that needs to be specified in the encoding format.

Gains:Try to prevent Garbled text before sending a request from the client. Otherwise, it will be very difficult for the background to transfer the Garbled text out of Chinese!

Filters in web. xml files are generally used to filter Garbled text in post requests and cannot filter Garbled text in get requests.

Although many problems seem common and simple, they may become the killer of wasting your precious time.

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.