File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Getting Domain name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting Domain name" Watch "Getting Domain name" New topic

Getting Domain name

Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 112
Hi All,
I want to construct a link back to my site. So how can I get a domain name from the URL. My url looks like something below.

skild2 is the name of the war file deployed at I am using the following code but I am always getting it as a localhost and not I am using the following pieces of codes.


Any ideas on this? Thanks in advance BTW.

Regards, Fawad Ali.
Software Engineer, Stafona Inc. - My Blog
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63061

Rather than going through all the hoops with the URL class, perhaps there is a more direct approach? Hint: look at the other methods on HttpServletRequest.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Getting Domain name
It's not a secret anymore!