servletcontext.html

来自「SUN公司官方J2EE中文帮助文档 应该不错 有兴趣的下来看看 html格式的」· HTML 代码 · 共 935 行 · 第 1/3 页

HTML
935
字号
			instead.

 <p>This method was originally defined to write an 
 exception's stack trace and an explanatory error message
 to the servlet log file.</I></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#log(java.lang.String)">log</A></B>(java.lang.String&nbsp;msg)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Writes the specified message to a servlet log file, usually
 an event log.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#log(java.lang.String, java.lang.Throwable)">log</A></B>(java.lang.String&nbsp;message,
    java.lang.Throwable&nbsp;throwable)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Writes an explanatory message and a stack trace
 for a given <code>Throwable</code> exception
 to the servlet log file.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#removeAttribute(java.lang.String)">removeAttribute</A></B>(java.lang.String&nbsp;name)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Removes the attribute with the given name from 
 the servlet context.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#setAttribute(java.lang.String, java.lang.Object)">setAttribute</A></B>(java.lang.String&nbsp;name,
             java.lang.Object&nbsp;object)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Binds an object to a given attribute name in this servlet context.</TD>
</TR>
</TABLE>
&nbsp;
<P>

<!-- ============ FIELD DETAIL =========== -->


<!-- ========= CONSTRUCTOR DETAIL ======== -->


<!-- ============ METHOD DETAIL ========== -->

<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=1><FONT SIZE="+2">
<B>Method Detail</B></FONT></TD>
</TR>
</TABLE>

<A NAME="getContext(java.lang.String)"><!-- --></A><H3>
getContext</H3>
<PRE>
public <A HREF="../../javax/servlet/ServletContext.html">ServletContext</A> <B>getContext</B>(java.lang.String&nbsp;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 <A HREF="../../javax/servlet/RequestDispatcher.html"><CODE>RequestDispatcher</CODE></A> 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.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>uripath</CODE> - 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 either
none exists or the container wishes to restrict 
 			this access.<DT><B>See Also: </B><DD><A HREF="../../javax/servlet/RequestDispatcher.html"><CODE>RequestDispatcher</CODE></A></DL>
</DD>
</DL>
<HR>

<A NAME="getMajorVersion()"><!-- --></A><H3>
getMajorVersion</H3>
<PRE>
public int <B>getMajorVersion</B>()</PRE>
<DL>
<DD>Returns the major version of the Java Servlet API that this
 servlet container supports. All implementations that comply
 with Version 2.3 must have this method
 return the integer 2.<DD><DL>
<DT><B>Returns:</B><DD>2</DL>
</DD>
</DL>
<HR>

<A NAME="getMinorVersion()"><!-- --></A><H3>
getMinorVersion</H3>
<PRE>
public int <B>getMinorVersion</B>()</PRE>
<DL>
<DD>Returns the minor version of the Servlet API that this
 servlet container supports. All implementations that comply
 with Version 2.3 must have this method
 return the integer 3.<DD><DL>
<DT><B>Returns:</B><DD>3</DL>
</DD>
</DL>
<HR>

<A NAME="getMimeType(java.lang.String)"><!-- --></A><H3>
getMimeType</H3>
<PRE>
public java.lang.String <B>getMimeType</B>(java.lang.String&nbsp;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>.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>file</CODE> - 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>
<HR>

<A NAME="getResourcePaths(java.lang.String)"><!-- --></A><H3>
getResourcePaths</H3>
<PRE>
public java.util.Set <B>getResourcePaths</B>(java.lang.String&nbsp;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><DD><DL>
<DT><B>Parameters:</B><DD><CODE>the</CODE> - 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.<DT><B>Since: </B><DD>Servlet 2.3</DD>
</DL>
</DD>
</DL>
<HR>

<A NAME="getResource(java.lang.String)"><!-- --></A><H3>
getResource</H3>
<PRE>
public java.net.URL <B>getResource</B>(java.lang.String&nbsp;path)
                         throws java.net.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. 

 <p>The servlet container must implement the URL handlers
 and <code>URLConnection</code> objects that are necessary
 to access the resource.

 <p>This method returns <code>null</code>
 if no resource is mapped to the pathname.

 <p>Some containers may allow writing to the URL returned by
 this method using the methods of the URL class.

 <p>The resource content is returned directly, so be aware that 
 requesting a <code>.jsp</code> page returns the JSP source code.
 Use a <code>RequestDispatcher</code> instead to include results of 
 an execution.

 <p>This method has a different purpose than
 <code>java.lang.Class.getResource</code>,
 which looks up resources based on a class loader. This
 method does not use class loaders.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>path</CODE> - a <code>String</code> specifying
						the path to the resource<DT><B>Returns:</B><DD>the resource located at the named path,
 						or <code>null</code> if there is no resource
						at that path<DT><B>Throws:</B><DD><CODE>java.net.MalformedURLException</CODE> - if the pathname is not given in 
 						the correct form</DL>
</DD>
</DL>
<HR>

<A NAME="getResourceAsStream(java.lang.String)"><!-- --></A><H3>
getResourceAsStream</H3>
<PRE>
public java.io.InputStream <B>getResourceAsStream</B>(java.lang.String&nbsp;path)</PRE>
<DL>
<DD>Returns the resource located at the named path as
 an <code>InputStream</code> object.

 <p>The data in the <code>InputStream</code> can be 
 of any type or length. The path must be specified according
 to the rules given in <code>getResource</code>.
 This method returns <code>null</code> if no resource exists at
 the specified path. 
 
 <p>Meta-information such as content length and content type
 that is available via <code>getResource</code>
 method is lost when using this method.

 <p>The servlet container must implement the URL handlers
 and <code>URLConnection</code> objects necessary to access
 the resource.

 <p>This method is different from 
 <code>java.lang.Class.getResourceAsStream</code>,
 which uses a class loader. This method allows servlet containers 
 to make a resource available
 to a servlet from any location, without using a class loader.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>name</CODE> - a <code>String</code> specifying the path
			to the resource<DT><B>Returns:</B><DD>the <code>InputStream</code> returned to the 
			servlet, or <code>null</code> if no resource
			exists at the specified path</DL>
</DD>
</DL>
<HR>

<A NAME="getRequestDispatcher(java.lang.String)"><!-- --></A><H3>
getRequestDispatcher</H3>
<PRE>
public <A HREF="../../javax/servlet/RequestDispatcher.html">RequestDispatcher</A> <B>getRequestDispatcher</B>(java.lang.String&nbsp;path)</PRE>
<DL>
<DD>Returns a <A HREF="../../javax/servlet/RequestDispatcher.html"><CODE>RequestDispatcher</CODE></A> object that acts
 as a wrapper for the resource located at the given path.
 A <code>RequestDispatcher</code> object can be used to forward 
 a request to the resource or to include the resource in a response.
 The resource can be dynamic or static.

 <p>The pathname must begin with a "/" and is interpreted as relative
 to the current context root.  Use <code>getContext</code> to obtain
 a <code>RequestDispatcher</code> for resources in foreign contexts.
 This method returns <code>null</code> if the <code>ServletContext</code>
 cannot return a <code>RequestDispatcher</code>.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>path</CODE> - a <code>String</code> specifying the pathname
			to the resource<DT><B>Returns:</B><DD>a <code>RequestDispatcher</code> object
			that acts as a wrapper for the resource
			at the specified path<DT><B>See Also: </B><DD><A HREF="../../javax/servlet/RequestDispatcher.html"><CODE>RequestDispatcher</CODE></A>, 
<A HREF="../../javax/servlet/ServletContext.html#getContext(java.lang.String)"><CODE>getContext(java.lang.String)</CODE></A></DL>
</DD>
</DL>
<HR>

<A NAME="getNamedDispatcher(java.lang.String)"><!-- --></A><H3>
getNamedDispatcher</H3>
<PRE>
public <A HREF="../../javax/servlet/RequestDispatcher.html">RequestDispatcher</A> <B>getNamedDispatcher</B>(java.lang.String&nbsp;name)</PRE>
<DL>
<DD>Returns a <A HREF="../../javax/servlet/RequestDispatcher.html"><CODE>RequestDispatcher</CODE></A> object that acts
 as a wrapper for the named servlet.

 <p>Servlets (and JSP pages also) may be given names via server 
 administration or via a web application deployment descriptor.
 A servlet instance can determine its name using 
 <A HREF="../../javax/servlet/ServletConfig.html#getServletName()"><CODE>ServletConfig.getServletName()</CODE></A>.

 <p>This method returns <code>null</code> if the 
 <code>ServletContext</code>
 cannot return a <code>RequestDispatcher</code> for any reason.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>name</CODE> - a <code>String</code> specifying the name
			of a servlet to wrap<DT><B>Returns:</B><DD>a <code>RequestDispatcher</code> object
			that acts as a wrapper for the named servlet<DT><B>See Also: </B><DD><A HREF="../../javax/servlet/RequestDispatcher.html"><CODE>RequestDispatcher</CODE></A>, 
<A HREF="../../javax/servlet/ServletContext.html#getContext(java.lang.String)"><CODE>getContext(java.lang.String)</CODE></A>, 
<A HREF="../../javax/servlet/ServletConfig.html#getServletName()"><CODE>ServletConfig.getServletName()</CODE></A></DL>
</DD>
</DL>
<HR>

<A NAME="getServlet(java.lang.String)"><!-- --></A><H3>
getServlet</H3>
<PRE>
public <A HREF="../../javax/servlet/Servlet.html">Servlet</A> <B>getServlet</B>(java.lang.String&nbsp;name)
                   throws <A HREF="../../javax/servlet/ServletException.html">ServletException</A></PRE>
<DL>
<DD><B>Deprecated.</B>&nbsp;<I>As of Java Servlet API 2.1, with no direct replacement.

 <p>This method was originally defined to retrieve a servlet
 from a <code>ServletContext</code>. In this version, this method 
 always returns <code>null</code> and remains only to preserve 
 binary compatibility. This method will be permanently removed 
 in a future version of the Java Servlet API.

 <p>In lieu of this method, servlets can share information using the 
 <code>ServletContext</code> class and can perform shared business logic
 by invoking methods on common non-servlet classes.</I>
<P>
</DL>
<HR>

<A NAME="getServlets()"><!-- --></A><H3>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?