首页 > Web开发 > 详细

获取url中的query string

时间:2016-03-19 02:08:22      阅读:387      评论:0      收藏:0      [点我收藏+]

获取url中的query string

util方法:

/***
	 * convert request query string to map
	 * 
	 * @param queryString
	 * @return
	 */
	public static Map<String, Object> parseQueryString(String queryString) {
		if (ValueWidget.isNullOrEmpty(queryString)) {
			return null;
		}
		int index = queryString.indexOf("?");
		if (index != SystemHWUtil.NEGATIVE_ONE) {
			queryString = queryString.substring(index + 1);
		}
		
		Map<String, Object> argMap = new HashMap<String, Object>();
		String[] queryArr = queryString.split("&");
		for (int i = 0; i < queryArr.length; i++) {
			String string = queryArr[i];
			String keyAndValue[] = string.split("=", 2);
			if (keyAndValue.length != 2) {
				argMap.put(keyAndValue[0], EMPTY);
			} else {
				argMap.put(keyAndValue[0], keyAndValue[1]);
			}
		}
		return argMap;
	}

?

测试:

@Test
	public  void test_queryString(){
		String url="orderId=INTE2016031800025&orgId=90001001119";

		Map<String, Object> argMap =SystemHWUtil.parseQueryString(url);
		System.out.println(argMap);
	}

?运行结果:{orgId=90001001119, orderId=INTE2016031800025}

?

@Test
	public  void test_queryString(){
		String url="http://store.chanjet.com/order/startPay?orderId=INTE2016031701837&payType=chanpay&orgId=90001001032&callack= ";
		Map<String, Object> argMap =SystemHWUtil.parseQueryString(url);
		System.out.println(argMap);
	}

运行结果:{orgId=90001001032, callack= , payType=chanpay, orderId=INTE2016031701837}

?

?

?

?

获取url中的query string

原文:http://hw1287789687.iteye.com/blog/2284563

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!