Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Request server port methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Request server port methods" Watch "Request server port methods" New topic

Request server port methods

Vinay Joseph

Joined: Jun 05, 2006
Posts: 4
What are the following methods used for: request.getServerPort(), request.getRemotePort() & request.getLocalPort()? What's the difference between these methods?
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

getRemoteport() and getLocalPort() are new mehtods of javax.servlet.ServletRequest interface in Servlet 2.4:

getServerName and getServerPort methods returned values that getLocalName and getLocalPort now do. In version 2.4, getServerName and getServerPort have been redefined. Check the API documentation for more information.

for more description of these methods check this..
New Features in Servlet 2.4

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Khaled Mahmoud
Ranch Hand

Joined: Jul 15, 2006
Posts: 361
When type a url in the browser's address bar, for example
The browser opens a socket connection to the server at port 8082, (The port on which the server is listening.Then the browser redirects you to another port because that port is especially for listening to requests and then making redirection

getServerPort returns the port on which the web server is listening
getRemotePort returns the port at which the client is connection with you
getLocalPort returns the the port after redirection.

Hope that the information was useful

Life is the biggest school
I agree. Here's the link:
subject: Request server port methods
It's not a secret anymore!