getUrl using Java

Tsundoku picture Tsundoku · Nov 2, 2008 · Viewed 12.7k times · Source

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

Answer

Paul Croarkin picture Paul Croarkin · Nov 2, 2008

The question is not really clear, but I'll make the assumption that you are trying to get the path from within a Servlet.

String realPath = getServletConfig().getServletContext().getRealPath(relativePath);