📄 servletcontext.html
字号:
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.
<P>
<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 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.
<P>
<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 <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" title="interface in javax.servlet">RequestDispatcher</A> <B>getRequestDispatcher</B>(java.lang.String path)</PRE>
<DL>
<DD>Returns a <A HREF="../../javax/servlet/RequestDispatcher.html" title="interface in javax.servlet"><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>.
<P>
<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, or <code>null</code> if
the <code>ServletContext</code> cannot return
a <code>RequestDispatcher</code><DT><B>See Also:</B><DD><A HREF="../../javax/servlet/RequestDispatcher.html" title="interface in javax.servlet"><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" title="interface in javax.servlet">RequestDispatcher</A> <B>getNamedDispatcher</B>(java.lang.String name)</PRE>
<DL>
<DD>Returns a <A HREF="../../javax/servlet/RequestDispatcher.html" title="interface in javax.servlet"><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.
<P>
<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,
or <code>null</code> if the <code>ServletContext</code>
cannot return a <code>RequestDispatcher</code><DT><B>See Also:</B><DD><A HREF="../../javax/servlet/RequestDispatcher.html" title="interface in javax.servlet"><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" title="interface in javax.servlet">Servlet</A> <B>getServlet</B>(java.lang.String name)
throws <A HREF="../../javax/servlet/ServletException.html" title="class in javax.servlet">ServletException</A></PRE>
<DL>
<DD><B>Deprecated.</B> <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>
<DD><DL>
<DT><B>Throws:</B>
<DD><CODE><A HREF="../../javax/servlet/ServletException.html" title="class in javax.servlet">ServletException</A></CODE></DL>
</DD>
</DL>
<HR>
<A NAME="getServlets()"><!-- --></A><H3>
getServlets</H3>
<PRE>
public java.util.Enumeration <B>getServlets</B>()</PRE>
<DL>
<DD><B>Deprecated.</B> <I>As of Java Servlet API 2.0, with no replacement.
<p>This method was originally defined to return an <code>Enumeration</code>
of all the servlets known to this servlet context. In this
version, this method always returns an empty enumeration and
remains only to preserve binary compatibility. This method
will be permanently removed in a future version of the Java
Servlet API.</I>
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="getServletNames()"><!-- --></A><H3>
getServletNames</H3>
<PRE>
public java.util.Enumeration <B>getServletNames</B>()</PRE>
<DL>
<DD><B>Deprecated.</B> <I>As of Java Servlet API 2.1, with no replacement.
<p>This method was originally defined to return an
<code>Enumeration</code>
of all the servlet names known to this context. In this version,
this method always returns an empty <code>Enumeration</code> and
remains only to preserve binary compatibility. This method will
be permanently removed in a future version of the Java Servlet API.</I>
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="log(java.lang.String)"><!-- --></A><H3>
log</H3>
<PRE>
public void <B>log</B>(java.lang.String msg)</PRE>
<DL>
<DD>Writes the specified message to a servlet log file, usually
an event log. The name and type of the servlet log file is
specific to the servlet container.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>msg</CODE> - a <code>String</code> specifying the
message to be written to the log file</DL>
</DD>
</DL>
<HR>
<A NAME="log(java.lang.Exception, java.lang.String)"><!-- --></A><H3>
log</H3>
<PRE>
public void <B>log</B>(java.lang.Exception exception,
java.lang.String msg)</PRE>
<DL>
<DD><B>Deprecated.</B> <I>As of Java Servlet API 2.1, use
<A HREF="../../javax/servlet/ServletContext.html#log(java.lang.String, java.lang.Throwable)"><CODE>log(String message, Throwable throwable)</CODE></A>
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>
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="log(java.lang.String, java.lang.Throwable)"><!-- --></A><H3>
log</H3>
<PRE>
public void <B>log</B>(java.lang.String message,
java.lang.Throwable throwable)</PRE>
<DL>
<DD>Writes an explanatory message and a stack trace
for a given <code>Throwable</code> exception
to the servlet log file. The name and type of the servlet log
file is specific to the servlet container, usually an event log.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>message</CODE> - a <code>String</code> that
describes the error or exception<DD><CODE>throwable</CODE> - the <code>Throwable</code> error
or exception</DL>
</DD>
</DL>
<HR>
<A NAME="getRealPath(java.lang.String)"><!-- --></A><H3>
getRealPath</H3>
<PRE>
public java.lang.String <B>getRealPath</B>(java.lang.String path)</PRE>
<DL>
<DD>Returns a <code>String</code> containing the real path
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -