开发者

What is the difference between ServletRequest's getRemoteHost() and getServerName()

开发者 https://www.devze.com 2022-12-21 09:18 出处:网络
The javadoc is a bit confusing t开发者_开发百科o me, and in my local tests it seems like they both return the same thing.What am I missing here?getRemoteHost returns the name of the client that sent t

The javadoc is a bit confusing t开发者_开发百科o me, and in my local tests it seems like they both return the same thing. What am I missing here?


getRemoteHost returns the name of the client that sent the request, while getServerName returns the name of the server that received the request.

It might be the same results in your local tests if you are using two machines on the network, one as a client and one for the server.


I'm not sure where this confusion is coming from, the javadoc is very explicit:

getRemoteHost():

Returns the fully qualified name of the client or the last proxy that sent the request.

getServerName():

Returns the host name of the server to which the request was sent.


They are both the same thing, because you runs both the client and server at the same machine.

0

精彩评论

暂无评论...
验证码 换一张
取 消