This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Servlets and the fly likes server name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "server name" Watch "server name" New topic

server name

Sunayna Kumar

Joined: Dec 13, 2001
Posts: 1
Help! I need to get the name of the server that my servlet is running on. Would anyone have example?
Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
I believe that it is
Biju Nair
Ranch Hand

Joined: Dec 15, 2001
Posts: 31
It is alwasys better to use the getServerPort() along with getServerName() as it will come handy if you use your port along with your server name ie. If you access your servlet as http://localhost:8080/servelt/myservlet, the getServerName() will give you only 'localhost' . In order to get the :8080 also, you have to use getServerName()+":"+getServerPort()


--: Biju Nair :--
I agree. Here's the link:
subject: server name
It's not a secret anymore!