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.
In a server that supports the concept of multiple hosts (and even
virtual hosts), the context must be at least as unique as the host.
Servlet engines may also provide context objects that are unique to
a group of servlets and which is tied to a specific portion of the
URL path namespace of the host. This grouping may be administratively
assigned or defined by deployment information.
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
-
getAttribute(String)
- Returns the value of the named attribute of the network service,
or null if the attribute does not exist.
-
getAttributeNames()
- Returns an enumeration of the attribute names present in the
network service.
-
getContext(String)
- Returns the ServletContext object for a particular uripath,
or null if there is not a ServletContext for the particular
path available or visible to this servlet.
-
getMajorVersion()
- Returns the major version of the servlet API that this
context supports.
-
getMimeType(String)
- Returns the mime type of the specified file, or null if not
known.
-
getMinorVersion()
- Returns the minor version of the servlet API that this context
supports.
-
getRealPath(String)
- Applies alias rules to the specified virtual path and returns the
corresponding real path.
-
getRequestDispatcher(String)
- Returns a request dispatcher to a server component accessible
via a URL path.
-
getResource(String)
- Returns a URL object allowing access to any content resource
requested.
-
getResourceAsStream(String)
- Returns an input stream to the given content resource path, or
null if not found.
-
getServerInfo()
- Returns the name and version of the network service under which
the servlet is running.
-
getServlet(String)
- This method has been deprecated and only remains to preserve
binary compatibility.
Deprecated.
-
getServletNames()
- This method has been deprecated and only remains to preserve
binary compatibility.
Deprecated.
-
getServlets()
- This method has been deprecated and only remains to preserve
binary compatibility.
Deprecated.
-
log(Exception, String)
- Write the stacktrace and the given message string to the
servlet log file.
Deprecated.
-
log(String)
- Writes the given message string to the servlet log file.
-
log(String, Throwable)
- Write the given message and stacktrace to the servlet log.
-
removeAttribute(String)
- Removes the attribute from the context that is bound to a particular
name.
-
setAttribute(String, Object)
- This method stores an attribute in the servlet context.
getContext
public abstract ServletContext getContext(String uripath)
- Returns the ServletContext object for a particular uripath,
or null if there is not a ServletContext for the particular
path available or visible to this servlet. This allows one
content to get RequestDispatchers and resources from another
context if so permitted. In more restricted environments, this
call may return null.
getMajorVersion
public abstract int getMajorVersion()
- Returns the major version of the servlet API that this
context supports.
- Returns:
- 2
getMimeType
public abstract 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
getMinorVersion
public abstract int getMinorVersion()
- Returns the minor version of the servlet API that this context
supports.
- Returns:
- 1
getResource
public abstract URL getResource(String path) throws MalformedURLException
- Returns a URL object allowing access to any content resource
requested. This method allows a servlet to access items in the
host servlet engine's document space in a system independent
way whether they reside on the local file system, a remote
file system, a database, or a remote network site without
knowing the specific details of how to obtain the resources.
The servlet engine must implement all of the specifics about
how to access the resource.
Only content resources known to this context object can
be accessed via this call.
The path parameter of this call must be a URL path. To
access the file index.html in the server's document root, the
call to this method would have the parameter "/index.html".
- Parameters:
- path - Path of the content resource
- Throws: MalformedURLException
- if the resource path is
not properly formed.
getResourceAsStream
public abstract InputStream getResourceAsStream(String path)
- Returns an input stream to the given content resource path, or
null if not found.
getRequestDispatcher
public abstract RequestDispatcher getRequestDispatcher(String urlpath)
- Returns a request dispatcher to a server component accessible
via a URL path. This method is typically used to obtain a
reference to another servlet. After obtaining a RequestDispatcher,
the servlet programmer forward a request to the target
component or include content from it.
This method will return null if the context cannot provide
a dispatcher for the path provided.
- Parameters:
- urlpath - Path to use to look up the target server resource
- See Also:
- RequestDispatcher
getServlet
public abstract Servlet getServlet(String name) throws ServletException
- Note: getServlet() is deprecated.
This method has been deprecated for security and
servlet lifecycle reasons. This method will be permanently
removed in a future version of the Servlet API.
- This method has been deprecated and only remains to preserve
binary compatibility. This method will always return null.
getServlets
public abstract Enumeration getServlets()
- Note: getServlets() is deprecated.
This method has been deprecated for security and
servlet lifecycle reasons. This method will be permanently
removed in a future version of the Servlet API.
- This method has been deprecated and only remains to preserve
binary compatibility. This method must always return an empty
enumeration.
getServletNames
public abstract Enumeration getServletNames()
- Note: getServletNames() is deprecated.
This method has been deprecated for security and
servlet lifecycle reasons. This method will be permanently
removed in a future version of the Servlet API.
- This method has been deprecated and only remains to preserve
binary compatibility. This methd must always return an
empty enumeration.
log
public abstract void log(String msg)
- Writes the given message string to the servlet log file.
The name and type of the servlet log file is server specific; it
is normally an event log.
- Parameters:
- msg - the message to be written
log
public abstract void log(Exception exception,
String msg)
- Note: log() is deprecated.
Use log(String message, Throwable t) instead
- 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
log
public abstract void log(String message,
Throwable throwable)
- Write the given message and stacktrace to the servlet log. The
name of the log is network service specific; it is typically
the event log.
- Parameters:
- msg - the message to be written
- throwable - the exception to be written
getRealPath
public abstract 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
getServerInfo
public abstract 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 abstract 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.
getAttributeNames
public abstract Enumeration getAttributeNames()
- Returns an enumeration of the attribute names present in the
network service.
setAttribute
public abstract void setAttribute(String name,
Object object)
- This method stores an attribute in the servlet context.
- Parameters:
- name - the name of the attribute to store
- value - the value of the attribute
removeAttribute
public abstract void removeAttribute(String name)
- Removes the attribute from the context that is bound to a particular
name.
- Parameters:
- name - the name of the attribute to remove from the context
All Packages Class Hierarchy This Package Previous Next Index