- 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
Reasons for escaping characters:
If your form is submitted using the Get method, and the arguments in the submission have a special character such as "&", if you do not do this, the service side will treat the & as a different parameter. For example
The action for 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 to act= ' go&state=5 ' This string, then to get the exact value of the act on the server, you must escape &
URL Escape Character principle:
These special characters are converted to 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 replaced with "2b%", so that the parameters to the server side can get "+".
Method Two, modify the server side, the space is replaced with "+", this method only applies to the parameter has "+" in the case of no spaces.
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, will get the method of the parameter by Reuqest. GetParameter to 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 and needs to be resolved 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