HttpServletRequest.getRemotePort()
How could a possible vendor 开发者_StackOverflow中文版implementation of HttpServletRequest.getRemotePort() get the remote port ? Is it parsed from the actual request sent ? I could not see any request headers like "Client-port", "Request-port" or the like.
The Web server receives the client's request using the normal mechanisms of TCP/IP. The client host and port are among the information that's available at that level. Having established the connection, the server packs it into the request information passed to your program.
The client doesn't send its port number, and even if it did it would be of dubious value because it would be very easy to fake for mischievous purposes. The port number is sent as part of the packets exchanged by TCP/IP stacks.
精彩评论