I am studying servlets, I have come up with a doubt difference between getLocalPort() and getServerPort().
Here the getLocalPort() means server side only then whats the meaning of getServerPort()?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In a simple setup (where your application server/servlet container accepts the request of the client directly) both methods will return the same value.
When the servlet container is not the application that accepts the client request (for example when you use an Apache HTTP server with mod_jk to accept the request and forward the request to a Tomcat instance via AJP), then
getServerPort()will return the port the client connected to (probably 80, when the default port is used) andgetLocalPort()will return the port that Tomcat used to accept the connection from the HTTP server (probably 8009 or something similar).