Parameter processing, url = "http: // 10.0.2.2: 8080/androidserver/music/Eason Chan-exaggerated"
In Chan yixun-exaggerated Before adding a URL, encode it first.
Example: String Mm = "Chan yixun-float ";
String Ss = urlencoder. encode (Mm, "UTF-8 "); // Here is the string encoded into a UTF-8
System. Out. println ("SS =" + SS );
// Output result Ss=chen Yi xunqiang -w.e6}�
// The space is encoded+ In this way, there is still a problem with the Space Encoding after the encoding, which needs to be processed. Continue below
Ss = ss. replaceall ("\\+ ","");// Because +Symbols are key characters in Java and must be escaped.
//It is the space encoding. If it is replaced here, no error will be reported for the URL.
Url = "http: /// 10.0.2.2: 8080/androidserver/music/" + SS
Such URL textThe space parameter problem is solved.
........................................................................................................................ ..................
URL special character escape and Solution
- Special characters in the URL must be escaped.
-
- 1. Replace space with the plus sign (+)
- 2. The forward slash (/) is used to separate directories and subdirectories.
- 3. Question mark (?) Separate URLs and queries
- 4. Specify special characters for the percent sign (% ).
- 5. # specifying bookmarks
- 6. & # separator Parameters
Causes of escape characters:
If your form is submitted using the get method and the submitted parameters contain special characters such, on the service end, the & parameter is treated as another parameter. For example
The form action is list. JSF? Act = Go & State = 5
Then, request. getparameter can be used to obtain the values of act and state.
If your intention is the act = 'go & State = 5' string, You must escape & to get the exact act value on the server.
Principles of URL escape characters:
Convert these special characters into ASCII codes in the format of % plus the ASCII code, that is, a percent sign %, followed by the ASCII (hexadecimal) value of the corresponding characters. For example, the Space Encoding value is "".
- The URL special symbol and the corresponding hexadecimal value encoding:
-
- 1.+ URL"+" Indicates space.+
- 2.SpaceSpaces in the URL can be encoded with a plus sign (+ ).
- 3./ Separate directories and subdirectories/
- 4.? Separate the actualURLAnd Parameters?
- 5.%Special characters%
- 6.#Indicates bookmarks#
- 7.&URLThe delimiter between the specified parameters in&
- 8.=URLParameter Value in=
Solution ):
Method 1,Modify the client and replace "+" in the "+" parameter of the client with "+" with "2B %". Then, when the parameter is uploaded to the server, "+" is displayed.
Method 2,Modify the server side and replace the space with "+". This method is only applicable when the parameter contains "+" and no space.
Example:
- StringA=Reuqest. getparameter ("clientstr"). Replace ('',' + ');
If the client is clientstr = test + OK, the value of a is test + OK;
Method 3,Modify the server side, change the method for obtaining parameters from reuqest. getparameter to request. getquerystring (). substring (0), and parse the obtained string.
Example:
- StringA=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); The value of A is test + OK.
Appendix:A JavaScript code used to escape special characters in a URL.
- FunctionUrlencode (SSTR)
- {
- ReturnEscape (SSTR). Replace (/\ +/g,'+'). Replace (/\ "/g, '"'). Replace (/\ '/g,'''). Replace (///g ,'/');
- }