Two Laptop Bag*
The moose likes Servlets and the fly likes why getServerName() is part of ServletRequest? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "why getServerName() is part of ServletRequest?" Watch "why getServerName() is part of ServletRequest?" New topic
Author

why getServerName() is part of ServletRequest?

surendra vadlamudi
Greenhorn

Joined: Jan 05, 2005
Posts: 2
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

Joined: Dec 11, 2004
Posts: 13410

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 ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: why getServerName() is part of ServletRequest?