javax.servlet
Interface ServletContext


public interface ServletContext

A class created by the server to give servlets access to certain environment related objects and methods.
It contains standard information like the names of all the servlets, two kinds of log methods, the server name, etc.
The server can also store extra information here in the form of {String, Object} pairs. Different servlets can live in different ServletContexts, but a servlet engine can group related Servlets in the same ServletContext.
Servlet specific information can be transferred to a servlet using a class implementing the ServletConfig interface.

Since:
Servlet API 1.0
Version:
Servlet API 2.0

Method Summary
 java.lang.Object getAttribute(java.lang.String name)
          Gets the value of a named attribute
 java.lang.String getMimeType(java.lang.String filename)
          Gives the mimetype of the requested file
 java.lang.String getRealPath(java.lang.String virtualPath)
          Translates the requested virtual path to the real filesystem path using the servers knowledge of the document root.
 java.lang.String getServerInfo()
          A server supplied string containing the server name, version number, etc
 Servlet getServlet(java.lang.String name)
          Gets a specific servlet by name.
 java.util.Enumeration getServletNames()
          Gets all servlet names
 java.util.Enumeration getServlets()
          Deprecated. Always returns an empty Enumeration. Only the servlet engine should have references to Servlets.
 void log(java.lang.Exception exception, java.lang.String message)
          Writes an exception + message to the log
 void log(java.lang.String message)
          Writes a message to the log
 

Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Gets the value of a named attribute
Parameters:
name - the name of the attribute
Returns:
the value of the attribute or null if there is no attribute with this name
Since:
Servlet API 1.0

getMimeType

public java.lang.String getMimeType(java.lang.String filename)
Gives the mimetype of the requested file
Parameters:
filename - the file
Returns:
a String containing the mime type or null if the mime type cannot be determined
Since:
Servlet API 1.0

getRealPath

public java.lang.String getRealPath(java.lang.String virtualPath)
Translates the requested virtual path to the real filesystem path using the servers knowledge of the document root.
Parameters:
virtualPath - the path to be translated (e.g. /graphics/baby-gnu.png)
Returns:
the translated real filesystem path or null if the real system path cannot be found
Since:
Servlet API 1.0

getServerInfo

public java.lang.String getServerInfo()
A server supplied string containing the server name, version number, etc
Returns:
the string
Since:
Servlet API 1.0

log

public void log(java.lang.String message)
Writes a message to the log
Parameters:
message - the message to write
Since:
Servlet API 1.0

log

public void log(java.lang.Exception exception,
                java.lang.String message)
Writes an exception + message to the log
Parameters:
exception - the exception
message - the message
Since:
Servlet API 2.0

getServlet

public Servlet getServlet(java.lang.String name)
                   throws ServletException
Gets a specific servlet by name. The Servlet is guaranteed to accept service requests.
Parameters:
name - the name of the wanted servlet
Returns:
null, used to return the servlet or null if not loaded.
Throws:
ServletException - if a servlet related error occured
Since:
Servlet API 1.0

getServlets

public java.util.Enumeration getServlets()
Deprecated. Always returns an empty Enumeration. Only the servlet engine should have references to Servlets.

Gets all servlets
Returns:
Empty Enumeration, used to return an enumeration containing all loaded servlets including the calling servlet.
Since:
Servlet API 1.0

getServletNames

public java.util.Enumeration getServletNames()
Gets all servlet names
Returns:
Empty Enumeration, used to return an enumeration containing all loaded servlet names including the calling servlet name
Since:
Servlet API 2.0