java模拟javascript的encodeURI方法
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class EncodeURI { public static void main(String args[]) throws UnsupportedEncodingException { String str = "\\zhong中文!@#~$%^&*()_+ "; System.out.println(encode(str)); System.out.println(URLEncoder.encode(str,"UTF8")); } public static String encode(String str) throws UnsupportedEncodingException{ String isoStr = new String(str.getBytes("UTF8"), "ISO-8859-1"); char[] chars = isoStr.toCharArray(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < chars.length; i++) { if ((chars[i] <= 'z' && chars[i] >= 'a') || (chars[i] <= 'Z' && chars[i] >= 'A') || chars[i] == '-' || chars[i] == '_' || chars[i] == '.' || chars[i] == '!' || chars[i] == '~' || chars[i] == '*' || chars[i] == '\'' || chars[i] == '(' || chars[i] == ')' || chars[i] == ';' || chars[i] == '/' || chars[i] == '?' || chars[i] == ':' || chars[i] == '@' || chars[i] == '&' || chars[i] == '=' || chars[i] == '+' || chars[i] == '$' || chars[i] == ',' || chars[i] == '#') { sb.append(chars[i]); } else { sb.append("%"); sb.append(Integer.toHexString(chars[i])); } } return sb.toString(); } }
相关推荐
angqiuli 2019-12-19
yicuncuntu0 2019-12-19
益之 2015-04-21
terabits的钵壳 2014-05-29
congweijing 2014-12-01
roodyszz0 2014-10-11
WillZhang 2014-08-09
roodyszz0 2014-05-15
lxpandsq 2014-04-21
liqing00 2010-11-18
honeyth 2014-03-31
80477204 2014-03-26
WillZhang 2014-03-17
}'这是取得Action穿过来的值,如果想取当前标题改为document.title. <a href="javascript:void" onclick="postToWb();" class="t
bossbusy 2014-03-12
herionliu 2013-09-10
谢恩铭 2013-07-11