0

I want to know if there is any way to get the real URL of a webpage. For example, I have a website named http://www.tutorialspoint.com/java/java_files_io.htm, the real/main URL is http://www.tutorialspoint.com of its main page.

Now I have another website http://www.sinhgad.edu/sinhgad-engineering-institutes/SEI-placement/index.html, its main page URL is http://www.sinhgad.edu/sinhgad-engineering-institutes/ in place of http://www.sinhgad.edu/ only.

I want to get this main page URL or real URL in Java.

marcospereira
  • 12,045
  • 3
  • 46
  • 52
anny
  • 21
  • 5

1 Answers1

0

In Java, you can use InetAddress.getLocalHost() to get the Ip Address of the current Server running the Java app and InetAddress.getHostName() to get Hostname of the current Server name.

source.

Albert Paul
  • 1,168
  • 13
  • 23
  • sir it will give my local server name. i want the main URL of a website which is running on that website's server. I want this using java code because i need to download the image files, scripting files, CSS and for that i need to get the exact path of that file. – anny Feb 20 '16 at 17:19
  • 1
    Try this answer, http://stackoverflow.com/questions/9607903/get-domain-name-from-given-url – Albert Paul Feb 20 '16 at 17:23
  • no this will not give me the complete path . See there is a file "http://www.sinhgad.edu/sinhgad-engineering-institutes/main.js" , i want to download that file but the problem is i am not getting the path of this file. because "http://www.sinhgad.edu/sinhgad-engineering-institutes/main.js" and "http://www.sinhgad.edu/main.js" both file are present on the server of singhad university. And i want the first one. – anny Feb 20 '16 at 17:46
  • actually i tried cases after splitting the URL which means i am checking that Is "http://www.sinhgad.edu/main.js" exist ? If not the check for "http://www.sinhgad.edu/sinhgad-engineering-institutes/main.js" . But here my first condition is being true but i want second condition. Thats why i was asking Is there any way of getting the main URL of the webpage so that i can get the real path to be appended before file. and after that i don't need to check the condition which i am checking. – anny Feb 20 '16 at 17:50