1.

How can a servlet get the name of the server and the port number for a particular request?

Answer»

A servlet can get the name of the server and the port number for a particular request with getServerName() and getServerPort(), respectively:

public STRING ServletRequest.getServerName()public int ServletRequest.getServerPort()

These METHODS are attributes of ServletRequest because the values can change for different requests if the server has more than one name (a TECHNIQUE called virtual hosting).

The getServerInfo() and getAttribute() methods of ServletContext supply INFORMATION about the server software and its attributes:

public String ServletContext.getServerInfo()public OBJECT ServletContext.getAttribute(String name)


Discussion

No Comment Found