URL special characters to be escaped
- 1. Replace the space with a plus sign (+)
- 2. Forward slash (/) separates directories and subdirectories
- 3. Question mark (?) Separating URLs and queries
- 4, percent semicolon (%) make special characters
- 5. #号指定书签
- 6, & Separation parameters
The reason for the
Escape character is:
If your form is submitted with a Get method and a special character such as "&" is present in the argument, the service side will treat the & as a different parameter if you do not do the processing. For example
The action of the form is list.jsf?act=go&state=5
the value of Act and state can be obtained separately by Request.getparameter when committing.
If your intention is act= ' go&state=5 ' This string, then in order to get the exact value of Act on the server, you must escape the &
URL escape character principle:
The
converts these special characters into ASCII code in the form of the ASCII code of the% plus character, which is a percent percent, followed by the ASCII (16 binary) code value of the corresponding character. For example, the encoded value of a space is "%20".
- URL special symbol and corresponding hexadecimal value encoding:
- 1. + URL + sign for space%2b
- 2. Spaces in the space URL can be used with the + number or code%20
- 3./separate directories and subdirectories%2f
- 4.? Separating the actual URLs and parameters%3f
- 5.% Specify special characters%25
- 6. # means bookmark%23
- 7. The delimiter between the parameters specified in the & URL%26
- 8. = value of the specified parameter in the URL%3d
The workaround is as follows (with the + number as an example):
Method One, modify the client, the client with "+" in the parameters of "+" all replace with? " 2b% ", so that when the parameter is passed to the server, it can get" + ".
Method Two, modify the server side, the space is replaced with "+", this method only applies to the parameters have? " + "There are no spaces in the case.
Example:
- String a = reuqest.? GetParameter ("Clientstr")? Replace (', ' + ');
If the client is Clientstr=test+ok, then the value of a is test+ok;
Method Three, modify the server side, the method to get the parameters from the reuqest. GetParameter instead of request.getquerystring (). substring (0), and parse the resulting string.
Example:
- ?? String a =request.getquerystring (). substring (0);
? If the client is Clientstr=test+ok, then the value of a is? Clientstr=test+ok, you need to parse it again,
A=a.? SUBSTRING (10); Gets the value of a to Test+ok.
Attached: A JS that is used to escape special characters in the URL.
- ? function UrlEncode (SSTR)
- {
- Return Escape (SSTR). Replace (/\+/g, '%2b '). Replace (/\ "/g, '%22 '). Replace (/\ '/g, '%27 '). Replace (/\//g, '%2f ');
- }
URL special character escaping and solving method