使用 Java 获取 URL
有没有办法使用获取网站绝对 URL (http://www.domain.com/)爪哇? 因为我用谷歌搜索了一下,但我只遇到必须创建 2 或 3 个类来创建该函数=/
更新:
问题是我正在尝试创建一个爬虫,它将为我提供一些信息,其中我会比如获取从中获取信息的网页的 URL。 我正在用 JAVA 开发这个,我的意思是我想知道是否有一些 getUrl(); 或任何类似的方法来获取 Url,因为我知道这是可以完成的,但我只是编写了一个完整的其他类来检索 url,然后继承它并进一步使用它......希望它能让它更清楚
Is there a way of getting the websites absolute URL (http://www.domain.com/) using Java? because I've googled a bit but I only come across with having to make 2 or 3 classes to create that function =/
Update:
The thing is I am trying to create a crawler that will give me some information and among that I'd like to get the URL of the webpage it's getting the information from. I'm developing this in JAVA and what I meant to say was that I was wondering if there was some getUrl(); or any method like that to get me the Url, because I know it can be done but I've only done it writing a whole other class to retrieve the url and then inherit it and use it further...hope it made it clearer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您只需要 JSP 中的域,但是您可能会发现您需要整个 URL,包括前缀、域、路径和参数。 快速获得此信息的最简单方法是使用 Request 对象并构建它。 请参阅此处了解更多信息:
http://www.exforsys。 com/tutorials/jsp/jsp-request-object.html
这是 Sun 的 HttpServletRequest 接口上的 API:
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletRequest.html
I'm assuming you just want the domain from a JSP, however you may find you need the entire URL including the prefix, domain, path and parameters. The easiest way to get this quickly is to use the Request object and build it. Have a look here for more info:
http://www.exforsys.com/tutorials/jsp/jsp-request-object.html
Here is Sun's API on the HttpServletRequest interface:
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletRequest.html
这个问题不太清楚,但我会假设您正在尝试从 Servlet 内获取路径。
The question is not really clear, but I'll make the assumption that you are trying to get the path from within a Servlet.
你可以再详细一点吗? 你的问题指出:
通过“网站”您要查询哪个网站? 我可以看到多种解释你的问题的方法:
ETC...
Could you be more specific? Your question states:
By "the website" which website are you asking for? I can see multiple ways of interpreting your question:
etc...