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.
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()