Special URL Processing. For example, addactionpop.htm? Url = 'HTTP: // localhost: 8080/powerplayer. P3X? Tid = 1826 & cid = 152728 &

Source: Internet
Author: User
Now, let's share with you some of the problems I have encountered today. Maybe you will encounter O (∩ _ ∩) o... haha handles a URL request and the playback address of the URL sent by the other party. This problem has not been found after the program has been completed for so long. Today, a playback address cannot be accessed from a server in a certain place. Page source code: <a href = "addactionpop.htm? URL =$ {mobilepop. vovod_url} & code =$ {mobilepop. code} "class =" A1 "> </a> URL is a complete parameter. But the parameter he sent to me is: http: // localhost/powerplayer. P3X? Tid = 1826 & cid = 152728 & FID = 376424 & code = Ssssss. After arriving at the background, this URL will be parsed into two codeo (encoding _ encoding) O... What do you already understand? Handling of special character attaching: Package com. Mobile. util; public class escapeunescape {
Public static string escape (string SRC ){
Int I;
Char J;
Stringbuffer TMP = new stringbuffer ();
TMP. ensurecapacity (SRC. Length () * 6 );
For (I = 0; I <SRC. Length (); I ++ ){
J = SRC. charat (I );
If (character. isdigit (j) | character. islowercase (j)
| Character. isuppercase (j ))
TMP. append (j );
Else if (j <256 ){
TMP. append ("% ");
If (j <16)
TMP. append ("0 ");
TMP. append (integer. tostring (J, 16 ));
} Else {
TMP. append ("% u ");
TMP. append (integer. tostring (J, 16 ));
}
}
Return TMP. tostring ();
} Public static string Unescape (string SRC ){
Stringbuffer TMP = new stringbuffer ();
TMP. ensurecapacity (SRC. Length ());
Int lastpos = 0, Pos = 0;
Char ch;
While (lastpos <SRC. Length ()){
Pos = SRC. indexof ("%", lastpos );
If (Pos = lastpos ){
If (SRC. charat (Pos + 1) = 'U '){
Ch = (char) integer. parseint (SRC
. Substring (Pos + 2, POS + 6), 16 );
TMP. append (CH );
Lastpos = POS + 6;
} Else {
Ch = (char) integer. parseint (SRC
. Substring (Pos + 1, POS + 3), 16 );
TMP. append (CH );
Lastpos = POS + 3;
}
} Else {
If (Pos =-1 ){
TMP. append (SRC. substring (lastpos ));
Lastpos = SRC. Length ();
} Else {
TMP. append (SRC. substring (lastpos, POS ));
Lastpos = Pos;
}
}
}
Return TMP. tostring ();
} Public static void main (string [] ARGs ){
String TMP = "? ";
System. Out. println ("testing escape:" + TMP );
TMP = escape (TMP );
System. Out. println (TMP );
System. Out. println ("testing Unescape:" + TMP );
System. Out. println (Unescape (TMP ));
}}

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.