JS processing url Chinese parameter Java side receive processing

Source: Internet
Author: User

Normally when the HTTP request with the Chinese parameter, the browser will automatically encode the Chinese language (according to the current page of the pageencoding), the Java side container will connect to the parameters received automatically once transcoding, Then the request.getparameter fetch is the normal data

If the browser does not automatically encode the Chinese, then the Java end of the automatic transcoding will appear garbled, at this time you can use encodeURI in JS to encode Chinese, the background without forcing decoding, you can normally fetch data, because there is no Chinese data after manual encoding, Does not affect browsers that are encoded by default

Normally,  send  encodeuricomponent (parmename) + "=" +encodeuricomponent (parmevalue); The
,  Direct  string paramvalue = request.getparameter (paramname); //  container is automatically decoded when it is received.

We know that  encodeURIComponent  uses  UTF-8  encoding rules to encode.
If  request.getparameter (paramname)  , the container also presses  UTF-8  solution, is correct.

If  request.getparameter (paramname), the container does not press  UTF-8  solution Words,  result only one, is garbled!
What encoding the container decodes is determined by the  request.setcharacterencoding (* * *)   or   server program configuration.

If you are able to  request.setcharacterencoding ("UTF-8"),  and   Modify the server configuration in the  jsp  program, let the container in the solution   get  the arguments submitted, use  utf-8.

If, for the project, you cannot specify what encoding rules the container uses to decode the submitted parameters, such as when you need to receive the contents of a parameter that is not encoded from a different page. (or the developers are confused by this somewhat complex stuff, do not know how to do the right to do the work of receiving parameters)
At this point, the parameters are encoded two times on the client side, which effectively avoids the thorny issue of "committing multibyte characters."
Because the first time you encode, your parameter content does not have multibyte characters and becomes a purely Ascii string. (This is the first time the result is called [str_enc1] good. [STR_ENC1] is not a multibyte character)
Once again, submit, receive the container automatic solution once (the container automatic solution this time, whether it is to press GBK or UTF-8 or iso-8859-1 are good, can correctly get [str_enc1])
Then, implement the decodeURIComponent once in the program (usually using Java.net.URLDecoder (* * *, "UTF-8") in Java to get the original value of the parameter you want to commit.

JS processing url Chinese parameter Java side receive processing

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.