本文介绍了在java中获取URL参数并从该URL中提取特定文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网址,我需要从此网址获取v的值。
这是我的网址: http://www.youtube.com/watch?v=_RCIP6OrQrE

I have a URL and I need to get the value of v from this URL.Here is my URL: http://www.youtube.com/watch?v=_RCIP6OrQrE

任何有用且富有成效的帮助都受到高度赞赏..

Any useful and fruitful help is highly appreciated..

推荐答案

我认为最简单的方法之一就是解析 URL.getQuery() as

I think the one of the easiest ways out would be to parse the string returned by URL.getQuery() as

public static Map<String, String> getQueryMap(String query)
{
    String[] params = query.split("&");
    Map<String, String> map = new HashMap<String, String>();
    for (String param : params)
    {
        String name = param.split("=")[0];
        String value = param.split("=")[1];
        map.put(name, value);
    }
    return map;
}

您可以使用此函数返回的地图来检索键入的值。参数名称。

You can use the map returned by this function to retrieve the value keying in the parameter name.

这篇关于在java中获取URL参数并从该URL中提取特定文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多