CSDN博客

img NetSniffer

UTF-8参数解码的例子

发表于2004/10/14 9:23:00  1139人阅读

分类: WEB开发[JSP/PHP..]

<%!public static String decode(String s,String encoding) throws Exception {
StringBuffer sb = new StringBuffer();
for(int i=0; i<s.length(); 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容器以ISO8859_1处理HTTP GET/POST参数的编码方式
return new String(inputBytes,encoding);
}
%>
阅读全文
0 0

相关文章推荐

img
取 消
img