Java examples for java.net:URL Query
extract Value From Query String And Key
//package com.java2s; import java.util.StringTokenizer; public class Main { public static void main(String[] argv) { String key = "abc"; String queryString = "&abc=java2s.com"; System.out.println(extractValueFromQueryStringAndKey(key, queryString));/* w w w . ja v a2s . com*/ } public static String extractValueFromQueryStringAndKey(String key, String queryString) { String foundValue = null; StringTokenizer queryItems = new StringTokenizer(queryString, "&"); while (queryItems.hasMoreTokens() && foundValue == null) { String queryParameter = queryItems.nextToken(); StringTokenizer paramTokenizer = new StringTokenizer( queryParameter, "="); String currentKey = paramTokenizer.nextToken(); String currentValue = paramTokenizer.nextToken(); if (currentKey.equalsIgnoreCase(key)) { foundValue = currentValue; } } return foundValue; } }