Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

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.

See Also:
getServletConfig, getServletContext

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

Method Detail

getServlet

public 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

getServlets

public 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

getServletNames

public 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.


log

public 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

log

public 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

getRealPath

public 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

getMimeType

public 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

getServerInfo

public 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.

getAttribute

public 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.

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.