aspose file tools*
The moose likes Servlets and the fly likes Regarding method getLocalPort() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Regarding method getLocalPort()" Watch "Regarding method getLocalPort()" New topic
Author

Regarding method getLocalPort()

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi i came to know about getLocalPort() method that
I took help from "Head First Servlet and JSP" but didn't work out.

getLocalPort() ---> It says "on which port did the request END UP?"

What is the meaning of statement in above quotes??

Please explain in brief.

Thanks in Advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

"Jay", please check your private messages for an important administrative matter. Again.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Jay:
Hi i came to know about getLocalPort() method that
I took help from "Head First Servlet and JSP" but didn't work out.



why? anyways it gives your server port number

for example:

http://localhost:8081/webA/controller

then in controller request.getLocalPort() gives you 8081


Hope This Helps
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi Bear i think now thw name (Jay Shukla) looks fine to you.

And the method getLocalPort() is from ServletRequest Interface.

Any help greatly appreciated.


Thanks,
Jay.
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Thanks Sreetharaman for the reple.

But in the book (Head First...) They explain subtle differece between getServerPort() and getLocalPort() (both from ServletRequest Interface).

For the first method (getServerPort()) - "to which port was request originally SENT?".
As per the Head First ..."

"But there's differnce because although requests are sent to single port(Where the server is listning), the server turns aound and finds a different port for each thread so that the app can handle multiple clients at the same time".

In above quote if request was sent to one perticluar port than how server will able to listen that perticular request if it tries to find differnt port??

Thanks.

Jay.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Originally posted by seetharaman venkatasamy
http://localhost:8081/webA/controller

then in controller request.getLocalPort() gives you 8081

Not really.
request.getServerPort() will give 8081
Although request.getLocalPort() will give you 8081 sometimes but not all the time.

Hope this helps


SCJP, SCWCD.
|Asking Good Questions|
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks Amit Ghorpade
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Originally posted by seetharaman venkatasamy:
Thanks Amit Ghorpade


You are welcome
 
jQuery in Action, 2nd edition
 
subject: Regarding method getLocalPort()