Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in understanding some methods of ServletRequest

 
Ankit Mishra
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help me sort this thing out:

I have a url say

Case1:

http://wickedlysmart.com/servlets/serv.do

and another thing that request is coming from say 3303 port number and say the wickedlysmart IP address is: 192.1.2.3,

and in Servlet spec we have these methods:

getRemoteAddr()
getRemoteHost()
getRemotePort()
getServerName()
getLocalPort()
getLocalAddr()

now, from the above said url what these methods will return?

Case2:

I dont have the site name but i am having an IP address say

http://192.1.2.4/servlets/serv.do
with request coming from port no. say 3306
and what will the port 8080 will signify here?

i Have requested for serv.do now what will they return?

I have gone through the spec and tried working with my localhost stuff but Iam still not clear about this thing.

Please help me in this regard.
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletRequest API explains them all.
 
Ankit Mishra
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, for your reply.
I have gone through that but not able to clearly get the meaning as it doesn't explain it with an example.
So, it will be really grateful if you can give an insight to these methods.
I have even tried these methods on my machine but the thing is for remote and local i get the same thing since i am on single machine only.
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Methods with getReomteXXX() corresponds to the client where the request came from. "..Host()" methods correspond to the host name and "...Addr()" methods correspond to the IP address.
 
priya rishi
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ankit,

Servlets - is a Server side Program,so

1.any method like getServer... is always about the Server(very obvious)

2.any method like getLocal.. is again about the Server(local to Server is always Server , not the client.)

3.any method like getRemote.. is referring to the client(client is remote to the Server.)

Hope it helps.
 
Ankit Mishra
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vijitha and Priya for helping me out.
Ya i got some clarity now. Hope on practicing will make things more clearer. Thanks once again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic