Here you can find the source of extractParamsFromURI(String uri)
Parameter | Description |
---|---|
uri | The URI containing parameters |
public static String extractParamsFromURI(String uri)
//package com.java2s; /*//from w w w .j a va 2s . c om * Licensed to Laurent Broudoux (the "Author") under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Author licenses this * file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; public class Main { /** * Extract a dispatch rule string from URI parameters (specified using example values) * @param uri The URI containing parameters * @return A string representing dispatch rules for the corresponding incoming request. */ public static String extractParamsFromURI(String uri) { if (uri.contains("?") && uri.contains("=")) { String parameters = uri.substring(uri.indexOf("?") + 1); StringBuilder params = new StringBuilder(); for (String parameter : parameters.split("&")) { String[] pair = parameter.split("="); try { String key = URLDecoder.decode(pair[0], "UTF-8"); String value = URLDecoder.decode(pair[1], "UTF-8"); if (params.length() > 0) { params.append(" && "); } params.append(key); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return params.toString(); } return ""; } }