|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A servlet engine generated object that gives servlets information about their environment.
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.
Servlet.getServletConfig()
,
ServletConfig.getServletContext()
Method Summary | |
java.lang.Object |
getAttribute(java.lang.String name)
Returns an object that is known to the context by a given name, or null if there is no such object associated with the name. |
java.util.Enumeration |
getAttributeNames()
Returns an enumeration of the attribute names present in this context. |
ServletContext |
getContext(java.lang.String uripath)
Returns a ServletContext object for a particular URL path. |
int |
getMajorVersion()
Returns the major version of the servlet API that this servlet engine supports. |
java.lang.String |
getMimeType(java.lang.String file)
Returns the mime type of the specified file, or null if not known. |
int |
getMinorVersion()
Returns the minor version of the servlet API that this servlet engine supports. |
java.lang.String |
getRealPath(java.lang.String path)
Applies alias rules to the specified virtual path in URL path format, that is, /dir/dir/file.ext. |
RequestDispatcher |
getRequestDispatcher(java.lang.String urlpath)
Returns a RequestDispatcher object for the specified URL path if the context knows of an active source (such as a servlet, JSP page, CGI script, etc) of content for the particular path. |
java.net.URL |
getResource(java.lang.String path)
Returns a URL object of a resource that is mapped to a corresponding URL path. |
java.io.InputStream |
getResourceAsStream(java.lang.String path)
Returns an InputStream object allowing access to a resource that is mapped to a corresponding URL path. |
java.lang.String |
getServerInfo()
Returns the name and version of the network service under which the servlet is running. |
Servlet |
getServlet(java.lang.String name)
Deprecated. This method has been deprecated for servlet lifecycle reasons. This method will be permanently removed in a future version of the Servlet API. |
java.util.Enumeration |
getServletNames()
Deprecated. This method has been deprecated for servlet lifecycle reasons. This method will be permanently removed in a future version of the Servlet API. |
java.util.Enumeration |
getServlets()
Deprecated. This method has been deprecated for servlet lifecycle reasons. This method will be permanently removed in a future version of the Servlet API. |
void |
log(java.lang.Exception exception,
java.lang.String msg)
Deprecated. Use log(String message, Throwable t) instead |
void |
log(java.lang.String msg)
Logs the specified message to the context's log. |
void |
log(java.lang.String message,
java.lang.Throwable throwable)
Logs the specified message and a stack trace of the given Throwable object to the context's log. |
void |
removeAttribute(java.lang.String name)
Removes the attribute from the context that is bound to a particular name. |
void |
setAttribute(java.lang.String name,
java.lang.Object object)
Binds an object to a given name in this context. |
Method Detail |
public ServletContext getContext(java.lang.String uripath)
In security concious environments, the servlet engine may always return null for any given URL path.
uripath
- public int getMajorVersion()
public java.lang.String getMimeType(java.lang.String file)
file
- name of the file whose mime type is requiredpublic int getMinorVersion()
public java.net.URL getResource(java.lang.String path) throws java.net.MalformedURLException
This method may return null if there is no resource mapped to the given URL path.
The servlet engine must implement whatever URL handlers and URLConnection objects are necessary to access the given content.
This method does not fill the same purpose as the getResource method of java.lang.Class. The method in java.lang.Class looks up resources based on class loader. This method allows servlet engines to make resources avaialble to a servlet from any source without regards to class loaders, location, etc.
path
- Path of the content resourcepublic java.io.InputStream getResourceAsStream(java.lang.String path)
Note that meta-information such as content length and content type that are available when using the getResource method of this class are lost when using this method.
This method may return null if there is no resource mapped to the given URL path.
The servlet engine must implement whatever URL handlers and URLConnection objects are necessary to access the given content.
This method does not fill the same purpose as the getResourceAsStream method of java.lang.Class. The method in java.lang.Class looks up resources based on class loader. This method allows servlet engines to make resources avaialble to a servlet from any source without regards to class loaders, location, etc.
name
- public RequestDispatcher getRequestDispatcher(java.lang.String urlpath)
This method will return null if the context cannot provide a dispatcher for the path provided.
urlpath
- Path to use to look up the target server resourceRequestDispatcher
public Servlet getServlet(java.lang.String name) throws ServletException
public java.util.Enumeration getServlets()
public java.util.Enumeration getServletNames()
public void log(java.lang.String msg)
msg
- the message to be writtenpublic void log(java.lang.Exception exception, java.lang.String msg)
exception
- the exception to be writtenmsg
- the message to be writtenpublic void log(java.lang.String message, java.lang.Throwable throwable)
msg
- the message to be writtenthrowable
- the exception to be writtenpublic java.lang.String getRealPath(java.lang.String path)
This method returns null if the translation could not be performed for any reason.
path
- the virtual path to be translated into a real pathpublic java.lang.String getServerInfo()
public java.lang.Object getAttribute(java.lang.String name)
name
- the name of the attribute whose value is requiredpublic java.util.Enumeration getAttributeNames()
public void setAttribute(java.lang.String name, java.lang.Object object)
name
- the name of the attribute to storevalue
- the value of the attributepublic void removeAttribute(java.lang.String name)
name
- the name of the attribute to remove from the context
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |