url携带的参数获取并处理demo
url demo:
http://servername/webname/pagename.csp?paramName=paramValue¶mName2=paramName2¶mName3=paramName3
获取其中的参数:
String parameter = request.getQueryString();//只适用get请求
对参数的分割处理:
public static Map<String,String> getQueryParams(String parameter) { try { Map<String, String> params = new HashMap<String, String>(); for (String param : parameter.split("&")) { String[] pair = param.split("="); String key = URLDecoder.decode(pair[0], "UTF-8"); String value = ""; if (pair.length > 1) { value = URLDecoder.decode(pair[1], "UTF-8"); } params.put(key, value); } return params; } catch (UnsupportedEncodingException ex) { throw new AssertionError(ex); } }