【问题标题】:How to Find subapths in url [closed]如何在 url 中查找子路径 [关闭]
【发布时间】:2020-01-18 23:16:47
【问题描述】:

网址 url=新网址("http://www.google.com/stackoverflow/question");

输出

path1=stackoverflow, path2=问题,

另一个

网址 url=新网址("http://www.google.com/stackoverflow/question/java");

输出

path1=问题 path2=java

如果我们输入动态 url,我们如何才能找到这样的路径。 谢谢

【问题讨论】:

标签: java spring spring-boot url spring-rest


【解决方案1】:

请尝试下面的代码 -

public static void main(String[] args) throws Exception {

   URL aURL = new URL("http://www.google.com/stackoverflow/question");
    String[] pathSplit = aURL.getPath().split("/");
    System.out.println("path1 = " + pathSplit[1]);
    System.out.println("path2 = " + pathSplit[2]);
}

【讨论】:

    猜你喜欢
    • 2017-06-24
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多