• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding method getLocalPort()

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Jay", please check your private messages for an important administrative matter. Again.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Amit Ghorpade
 
Amit Ghorpade
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by seetharaman venkatasamy:
Thanks Amit Ghorpade



You are welcome
 
reply
    Bookmark Topic Watch Topic
  • New Topic