url携带的参数获取并处理demo

url demo:

http://servername/webname/pagename.csp?paramName=paramValue&paramName2=paramName2&paramName3=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);  
       }  
   }  

  

 

posted @ 2017-08-13 14:52  ATJAVA  阅读(642)  评论(0编辑  收藏  举报