UTF-8 parameter decoding example

xiaoxiao2021-03-06  95

<%! public static string decode (string s, string eNCoding) throws exception {

StringBuffer SB = new stringbuffer ();

For (int i = 0; i

CHAR C = S.Charat (i);

Switch (c) {

Case ' ':

sb.append ('');

Break;

Case '%':

Try {

sb.append ((char) integer.parseint

S.SUBSTRING (i 1, i 3), 16));

}

Catch (NumberFormatexception E) {

Throw new illegalargumentException ();

}

i = 2;

Break;

DEFAULT:

Sb.append (c);

Break;

}

}

// undo conversion to external encoding

String result = sb.toString ();

Byte [] INPUTBYTES = Result.getbytes ("8859_1"); // Web container with ISO8859_1 encoding method of HTTP GET / POST parameter

Return New String (InputBytes, Encoding);

}

%>

转载请注明原文地址:https://www.9cbs.com/read-106708.html

New Post(0)