Interface javax.servlet.ServletContext
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Interface javax.servlet.ServletContext

public interface ServletContext
The ServletContext interface gives servlets access to information about their environment, and allows them to log significant events. Servlet writers decide what data to log. The interface is implemented by services, and used by servlets. Different virtual hosts should have different servlet contexts.

Servlets get the ServletContext object via the getServletContext method of ServletConfig. The ServletConfig object is provided to the servlet at initialization, and is accessible via the servlet's getServletConfig method.

Version:
1.20, 10/09/97
See Also:
getServletConfig, getServletContext

Method Index

 o getAttribute(String)
Returns the value of the named attribute of the network service, or null if the attribute does not exist.
 o getMimeType(String)
Returns the mime type of the specified file, or null if not known.
 o getRealPath(String)
Applies alias rules to the specified virtual path and returns the corresponding real path.
 o getServerInfo()
Returns the name and version of the network service under which the servlet is running.
 o getServlet(String)
Returns the servlet of the specified name, or null if not found.
 o getServletNames()
Returns an enumeration of the Servlet object names in this server.
 o getServlets()
Returns an enumeration of the Servlet objects in this server.
 o log(String)
Writes the given message string to the servlet log file.
 o log(Exception, String)
Write the stacktrace and the given message string to the servlet log file.

Methods

 o getAttribute
public abstract java.lang.Object getAttribute(String name)
Returns the value of the named attribute of the network service, or null if the attribute does not exist. This method allows access to additional information about the service, not already provided by the other methods in this interface. Attribute names should follow the same convention as package names. The package names java.* and javax.* are reserved for use by Javasoft, and com.sun.* is reserved for use by Sun Microsystems.

Parameters:
name - the name of the attribute whose value is required
Returns:
the value of the attribute, or null if the attribute does not exist.
 o getMimeType
public abstract java.lang.String getMimeType(String file)
Returns the mime type of the specified file, or null if not known.

Parameters:
file - name of the file whose mime type is required
 o getRealPath
public abstract java.lang.String getRealPath(String path)
Applies alias rules to the specified virtual path and returns the corresponding real path. For example, in an HTTP servlet, this method would resolve the path against the HTTP service's docroot. Returns null if virtual paths are not supported, or if the translation could not be performed for any reason.

Parameters:
path - the virtual path to be translated into a real path
 o getServerInfo
public abstract java.lang.String getServerInfo()
Returns the name and version of the network service under which the servlet is running. For example, if the network service was an HTTP service, then this would be the same as the CGI variable SERVER_SOFTWARE.

 o getServlet
public abstract javax.servlet.Servlet getServlet(String name) throws ServletException
Returns the servlet of the specified name, or null if not found. When the servlet is returned it is initialized and ready to accept service requests.

Note: This is a dangerous method to call for the following reasons.

Parameters:
name - the name of the desired servlet
Throws: ServletException
if the servlet could not be initialized
 o getServletNames
public abstract java.util.Enumeration getServletNames()
Returns an enumeration of the Servlet object names in this server. Only servlets that are accessible (i.e., from the same namespace) will be returned. The enumeration always includes the servlet itself.

Note: This is a dangerous method to call for the following reasons.

 o getServlets
public abstract java.util.Enumeration getServlets()
Note: getServlets() is deprecated. Please use getServletNames in conjunction with getServlet

Returns an enumeration of the Servlet objects in this server. Only servlets that are accessible (i.e., from the same namespace) will be returned. The enumeration always includes the servlet itself.

Note: This is a dangerous method to call for the following reasons.

See Also:
getServletNames, getServlet
 o log
public abstract void log(String msg)
Writes the given message string to the servlet log file. The name of the servlet log file is server specific; it is normally an event log.

Parameters:
msg - the message to be written
 o log
public abstract void log(Exception exception,
                         String msg)
Write the stacktrace and the given message string to the servlet log file. The name of the servlet log file is server specific; it is normally an event log.

Parameters:
exception - the exception to be written
msg - the message to be written

All Packages  Class Hierarchy  This Package  Previous  Next  Index