📄 javax.servlet.servletcontext.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><!--NewPage--><html><head><!-- Generated by javadoc on Fri Apr 04 16:55:35 PST 2003 --><title> Interface javax.servlet.ServletContext</title></head><body><a name="_top_"></a><pre><a href="packages.html">All Packages</a> <a href="tree.html">Class Hierarchy</a> <a href="Package-javax.servlet.html">This Package</a> <a href="javax.servlet.ServletConfig.html#_top_">Previous</a> <a href="javax.servlet.ServletContextAttributeListener.html#_top_">Next</a> <a href="AllNames.html">Index</a></pre><hr><h1> Interface javax.servlet.ServletContext</h1><dl> <dt> public interface <b>ServletContext</b></dl>Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file. <p>There is one context per "web application" per Java Virtual Machine. (A "web application" is a collection of servlets and content installed under a specific subset of the server's URL namespace such as <code>/catalog</code> and possibly installed via a <code>.war</code> file.) <p>In the case of a web application marked "distributed" in its deployment descriptor, there will be one context instance for each virtual machine. In this situation, the context cannot be used as a location to share global information (because the information won't be truly global). Use an external resource like a database instead. <p>The <code>ServletContext</code> object is contained within the {@link ServletConfig} object, which the Web server provides the servlet when the servlet is initialized.<p><dl> <dt> <b>See Also:</b> <dd> <a href="javax.servlet.Servlet.html#getServletConfig">getServletConfig</a>, <a href="javax.servlet.ServletConfig.html#getServletContext">getServletContext</a></dl><hr><a name="index"></a><h2> <img src="images/method-index.gif" width=207 height=38 alt="Method Index"></h2><dl> <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getAttribute(javax.servlet.String)"><b>getAttribute</b></a>(String) <dd> Returns the servlet container attribute with the given name, or <code>null</code> if there is no attribute by that name. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getAttributeNames()"><b>getAttributeNames</b></a>() <dd> Returns an <code>Enumeration</code> containing the attribute names available within this servlet context. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getContext(javax.servlet.String)"><b>getContext</b></a>(String) <dd> Returns a <code>ServletContext</code> object that corresponds to a specified URL on the server. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getInitParameter(javax.servlet.String)"><b>getInitParameter</b></a>(String) <dd> Returns a <code>String</code> containing the value of the named context-wide initialization parameter, or <code>null</code> if the parameter does not exist. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getInitParameterNames()"><b>getInitParameterNames</b></a>() <dd> Returns the names of the context's initialization parameters as an <code>Enumeration</code> of <code>String</code> objects, or an empty <code>Enumeration</code> if the context has no initialization parameters. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getMajorVersion()"><b>getMajorVersion</b></a>() <dd> Returns the major version of the Java Servlet API that this servlet container supports. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getMimeType(javax.servlet.String)"><b>getMimeType</b></a>(String) <dd> Returns the MIME type of the specified file, or <code>null</code> if the MIME type is not known. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getMinorVersion()"><b>getMinorVersion</b></a>() <dd> Returns the minor version of the Servlet API that this servlet container supports. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getNamedDispatcher(javax.servlet.String)"><b>getNamedDispatcher</b></a>(String) <dd> Returns a { <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getRealPath(javax.servlet.String)"><b>getRealPath</b></a>(String) <dd> Returns a <code>String</code> containing the real path for a given virtual path. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getRequestDispatcher(javax.servlet.String)"><b>getRequestDispatcher</b></a>(String) <dd> Returns a { <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getResource(javax.servlet.String)"><b>getResource</b></a>(String) <dd> Returns a URL to the resource that is mapped to a specified path. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getResourceAsStream(javax.servlet.String)"><b>getResourceAsStream</b></a>(String) <dd> Returns the resource located at the named path as an <code>InputStream</code> object. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getResourcePaths(javax.servlet.String)"><b>getResourcePaths</b></a>(String) <dd> Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getServerInfo()"><b>getServerInfo</b></a>() <dd> Returns the name and version of the servlet container on which the servlet is running. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getServlet(javax.servlet.String)"><b>getServlet</b></a>(String) <dd> <b>Deprecated.</b> <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getServletContextName()"><b>getServletContextName</b></a>() <dd> Returns the name of this web application correponding to this ServletContext as specified in the deployment descriptor for this web application by the display-name element. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getServletNames()"><b>getServletNames</b></a>() <dd> <b>Deprecated.</b> <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#getServlets()"><b>getServlets</b></a>() <dd> <b>Deprecated.</b> <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#log(java.lang.Exception, javax.servlet.String)"><b>log</b></a>(Exception, String) <dd> <b>Deprecated.</b> <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#log(javax.servlet.String)"><b>log</b></a>(String) <dd> Writes the specified message to a servlet log file, usually an event log. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#log(javax.servlet.String, javax.servlet.Throwable)"><b>log</b></a>(String, Throwable) <dd> Writes an explanatory message and a stack trace for a given <code>Throwable</code> exception to the servlet log file. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#removeAttribute(javax.servlet.String)"><b>removeAttribute</b></a>(String) <dd> Removes the attribute with the given name from the servlet context. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#setAttribute(javax.servlet.String, java.lang.Object)"><b>setAttribute</b></a>(String, Object) <dd> Binds an object to a given attribute name in this servlet context.</dl><a name="methods"></a><h2> <img src="images/methods.gif" width=151 height=38 alt="Methods"></h2><a name="getContext(javax.servlet.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="getContext"><b>getContext</b></a><pre> public abstract <a href="#_top_">ServletContext</a> getContext(String uripath)</pre><dl> <dd> Returns a <code>ServletContext</code> object that corresponds to a specified URL on the server. <p>This method allows servlets to gain access to the context for various parts of the server, and as needed obtain {@link RequestDispatcher} objects from the context. The given path must be begin with "/", is interpreted relative to the server's document root and is matched against the context roots of other web applications hosted on this container. <p>In a security conscious environment, the servlet container may return <code>null</code> for a given URL.<p> <dd><dl> <dt> <b>Parameters:</b> <dd> uripath - a <code>String</code> specifying the context path of another web application in the container. <dt> <b>Returns:</b> <dd> the <code>ServletContext</code> object that corresponds to the named URL, or null if eithernone exists or the container wishes to restrict this access. <dt> <b>See Also:</b> <dd> <a href="javax.servlet.RequestDispatcher.html#_top_">RequestDispatcher</a> </dl></dd></dl><a name="getMajorVersion()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="getMajorVersion"><b>getMajorVersion</b></a><pre> public abstract int getMajorVersion()</pre><dl> <dd> Returns the major version of the Java Servlet API that this servlet container supports. All implementations that comply with Version 2.4 must have this method return the integer 2.<p> <dd><dl> <dt> <b>Returns:</b> <dd> 2 </dl></dd></dl><a name="getMinorVersion()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="getMinorVersion"><b>getMinorVersion</b></a><pre> public abstract int getMinorVersion()</pre><dl> <dd> Returns the minor version of the Servlet API that this servlet container supports. All implementations that comply with Version 2.4 must have this method return the integer 4.<p> <dd><dl> <dt> <b>Returns:</b> <dd> 4 </dl></dd></dl><a name="getMimeType(javax.servlet.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="getMimeType"><b>getMimeType</b></a><pre> public abstract String getMimeType(String file)</pre><dl> <dd> Returns the MIME type of the specified file, or <code>null</code> if the MIME type is not known. The MIME type is determined by the configuration of the servlet container, and may be specified in a web application deployment descriptor. Common MIME types are <code>"text/html"</code> and <code>"image/gif"</code>.<p> <dd><dl> <dt> <b>Parameters:</b> <dd> file - a <code>String</code> specifying the name of a file <dt> <b>Returns:</b> <dd> a <code>String</code> specifying the file's MIME type </dl></dd></dl><a name="getResourcePaths(javax.servlet.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="getResourcePaths"><b>getResourcePaths</b></a><pre> public abstract Set getResourcePaths(String path)</pre><dl> <dd> Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument. Paths indicating subdirectory paths end with a '/'. The returned paths are all relative to the root of the web application and have a leading '/'. For example, for a web application containing<br><br> /welcome.html<br> /catalog/index.html<br> /catalog/products.html<br> /catalog/offers/books.html<br> /catalog/offers/music.html<br> /customer/login.jsp<br> /WEB-INF/web.xml<br> /WEB-INF/classes/com.acme.OrderServlet.class,<br><br> getResourcePaths("/") returns {"/welcome.html", "/catalog/", "/customer/", "/WEB-INF/"}<br> getResourcePaths("/catalog/") returns {"/catalog/index.html", "/catalog/products.html", "/catalog/offers/"}.<br><p> <dd><dl> <dt> <b>Parameters:</b> <dd> the - partial path used to match the resources, which must start with a / <dt> <b>Returns:</b> <dd> a Set containing the directory listing, or null if there are no resources in the web application whose path begins with the supplied path. </dl></dd></dl><a name="getResource(javax.servlet.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="getResource"><b>getResource</b></a><pre> public abstract URL getResource(String path) throws MalformedURLException</pre><dl> <dd> Returns a URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root. <p>This method allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a <code>.war</code> file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -