• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getServerName(), getRemoteHost

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

What is the difference between HttpServletRequest.getServerName() and getRemoteHost()

The javadoc says:

-getServerName():Returns the host name of the server that received the request. For HTTP servlets, same as the value of the CGI variable SERVER_NAME.
-getRemoteHost():Returns the fully qualified name of the client that sent the request.

If I am sending the request from the same machine as the webserver is, shouldn't they be the same?
I get my machine name for getServerName(), while a totally different machine address from getRemoteHost().

Am i missing something here?
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Patel,

If the client and server are on same machine then
getServerName() returns the name(system's ip address) of your system
getRemoteHost() returns the fully qualified name(network name) of your system..

Example can be like
getServerName() 192.178.247.64
getRemoteHost() hostmdk76577.mycomp.com
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic