Solution to URL special character passing Parameters

Source: Internet
Author: User

Hexadecimal value
1. In the + URL, the plus sign indicates space % 2B
2. the space in the space URL can be + or encoded as % 20
3./separate directories and subdirectories % 2f
4 .? Separate the actual URL and parameter % 3f
5.% specify special characters % 25
6. # indicates bookmarks % 23
7. & separator between parameters specified in URL % 26
8. = value of the specified parameter in the URL % 3d

If you use Str. Replace ("-","! ") Will only Replace the first matched character.
Str. Replace (/\-/g ,"! "), You can replace all matched characters (G is the global flag ).
Replace ()
The replacement character variables in JS are as follows:

Data2 = data2.replace (/\ %/g, "% 25 ");
Data2 = data2.replace (// #/g, "% 23 ");
Data2 = data2.replace (// \ &/g, "% 26 ");

Other materials... For reference only...

When URL is used for parameter transfer, parameters or URL addresses of some Chinese names (or containing special characters) are often transmitted. Conversion errors may occur in background processing. In some transfer pages, gb2312 is used, and utf8 is used on the receiving page. In this way, the received parameters may be different from the original ones. The URL encoded using the urlencode function on the server is different from the URL encoded using the encodeuri function of the client Java.

Java Coding involves three functions: Escape, encodeuri, and encodeuricomponent. The corresponding three decoding functions are: Unescape, decodeuri, and decodeuricomponent.

Java encoding method:
Escape () method: uses the ISO Latin character set to encode the specified string. All space characters, punctuation marks, special characters, and other non-ASCII characters will be converted into character encoding in % XX format (XX equals to the hexadecimal encoding of this character in the character set table number ). For example, the space character is encoded as % 20. The Unescape method is the opposite. Characters not encoded by this method: @ */+

Encodeuri () method: converts a URI string into an escape string in UTF-8 encoding format. Characters not encoded by this method :! @ # $ & * () = :/;? +'

Encodeuricomponent () method: convert a URI string to an escape string in UTF-8 encoding format. Compared with encodeuri (), this method will encode more characters, such. Therefore, if the string contains several parts of the URI, this method cannot be used for encoding. Otherwise, the URL will display an error after the/character is encoded. Characters not encoded by this method :! *()

Therefore, for a Chinese string, if you do not want to convert the string encoding format to the UTF-8 format (for example, when the charset of the original page and the target page is consistent), you only need to use escape. If your page is gb2312 or another code, and the page that accepts the parameter is UTF-8 code, use encodeuri or encodeuricomponent.

In addition, encodeuri/encodeuricomponent is introduced after java1.5, and escape is available in java1.0.
1. encodeuricomponent is required when passing parameters so that the combined URL will not be truncated by special characters such.

Example: <Language = "Java"> write ('<a href = " /? Logout & Aid = 7 & U = '+ encodeuricomponent ("") +' "> exit </a> '); </>

2. encodeuri can be used for URL redirection.

Example: location. href = encodeuri (" WORD = Baidu & Ct = 21 ");

3. You can use escape when JS uses data.

For example, search for the history record in the bucket.

4. When encoding Unicode values other than 0-, escape outputs % u *** format. In other cases, escape, encodeuri, and encodeuricomponent have the same encoding result.

The most commonly used format is encodeuricomponent, which converts special characters such as Chinese and Korean into UTF-8 URL encoding, therefore, if you want to use encodeuricomponent to transmit parameters to the backend, you must use backend decoding to support UTF-8 (the encoding method in form is the same as that on the current page)

Escape does not encode 69 characters: *, + ,-,.

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: 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.