gpt4 book ai didi

java - 从 URL 获取路径的实用程序

转载 作者:行者123 更新时间:2023-12-01 17:24:21 30 4
gpt4 key购买 nike

我需要获取域名后面的路径。
例如:网址为https://vaadin.com:8080/wiki/-/wiki/Main/Authenticating+Vaadin-based+applications/pop_up
我想要获取 /wiki/-/wiki/Main/Authenticating+Vaadin-based+applications/pop_up。java 有没有 Utils 类可以快速做到这一点?非常感谢!

最佳答案

为什么不直接使用 URL 类的 getPath() 呢?参见这里:

http://docs.oracle.com/javase/6/docs/api/java/net/URL.html#getPath%28%29

Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as a query to a database or to a search engine. More information on the types of URLs and their formats can be found at:

http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html 

In general, a URL can be broken into several parts. The previous example of a URL indicates that the protocol to use is http (HyperText Transfer Protocol) and that the information resides on a host machine named www.socs.uts.edu.au. The information on that host machine is named /MosaicDocs-old/url-primer.html. The exact meaning of this name on the host machine is both protocol dependent and host dependent. The information normally resides in a file, but it could be generated on the fly. This component of the URL is called the path component.

关于java - 从 URL 获取路径的实用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16231757/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com