• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding method getLocalPort()

 
Jay Shukla
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Jay", please check your private messages for an important administrative matter. Again.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amit Ghorpade
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by seetharaman venkatasamy:
Thanks Amit Ghorpade


You are welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic