Less nonsense, go straight to the key code.
The specific code is as follows:
/*** Remove the path in the url and leave the request parameter part* @param strURL url address* @return url request parameter part* @author lzf*/private static String TruncateUrlPage(String strURL){String strAllParam=null;String[] arrSplit=null;strURL=strURL.trim().toLowerCase();arrSplit=strURL.split("[?]");if(strURL.length()>1){if(arrSplit.length>1){for (int i=1;i<arrSplit.length;i++){strAllParam = arrSplit[i];}}} return strAllParam; }/*** parse out the key-value pairs in the url parameters* For example, "index.jsp?Action=del&id=123", parse out the Action:del,id:123 stored in the map* @param URL url address* @return url request parameter part* @author lzf*/public static Map<String, String> urlSplit(String URL){Map<String, String> mapRequest = new HashMap<String, String>();String[] arrSplit=null;String strUrlParam=TruncateUrlPage(URL);if(strUrlParam==null){return mapRequest;}arrSplit=strUrlParam.split("[&]");for(String strSplit:arrSplit){String[] arrSplitEqual=null; arrSplitEqual=strSplit.split("[=]");//Parse out the key value if(arrSplitEqual.length>1){//Correctly parse mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]);}else{if(arrSplitEqual[0]!=""){//Only the parameters have no value, mapRequest.put(arrSplitEqual[0], ""); }}} return mapRequest; }PS: Java intercepts the value in the url
Map<String, Object> urlSplit(String data){StringBuffer strbuf = new StringBuffer();StringBuffer strbuf2 = new StringBuffer();Map<String,Object> map = new HashMap<String,Object>();for(int i =0;i<data.length();i++){if(data.substring(i,i+1).equals("=")){for(int n=i+1;n<data.length();n++){if(data.substring(n,n+1).equals("&")|| n ==data.length()-1){map.put(strbuf.toString(), strbuf2);strbuf =new StringBuffer("");strbuf2 =new StringBuffer("");i=n;break;}strbuf2.append(data.substring(n,n+1));}continue;}strbuf.append(data.substring(i,i+1));}return map;}The above is the method of intercepting url parameters in Java and the method of intercepting url values in Java. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!