Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why getServerName() is part of ServletRequest?

 
surendra vadlamudi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why getServerName() and getServerPort() methods are added as part of ServletRequest instead of ServletContext.I mean we will get Server info by ServletContext,and these provide info about Server.So why not these provide as part of ServletContext.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because those values are coming from the request headers:


SRV.14.2.16.1 Methods

getServerName()
public java.lang.String getServerName()
Returns the host name of the server to which the request was sent. It is the
value of the part before ":" in the Host header value, if any, or the resolved

server name, or the server IP address.
Returns: a String containing the name of the server

getServerPort()

public int getServerPort()
Returns the port number to which the request was sent. It is the value of the
part after ":" in the Host header value, if any, or the server port where the cli-
ent connection was accepted on.

Returns: an integer specifying the port number




[ January 14, 2005: Message edited by: Ben Souther ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic