📄 servletcontext.html
字号:
<BR>
Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path
matches the supplied path argument.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#getServerInfo()">getServerInfo</A></B>()</CODE>
<BR>
Returns the name and version of the servlet container on which
the servlet is running.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../javax/servlet/Servlet.html" title="interface in javax.servlet">Servlet</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#getServlet(java.lang.String)">getServlet</A></B>(java.lang.String name)</CODE>
<BR>
<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></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#getServletContextName()">getServletContextName</A></B>()</CODE>
<BR>
Returns the name of this web application corresponding to this ServletContext as specified in the deployment
descriptor for this web application by the display-name element.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> java.util.Enumeration</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#getServletNames()">getServletNames</A></B>()</CODE>
<BR>
<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></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> java.util.Enumeration</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#getServlets()">getServlets</A></B>()</CODE>
<BR>
<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></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#log(java.lang.Exception, java.lang.String)">log</A></B>(java.lang.Exception exception,
java.lang.String msg)</CODE>
<BR>
<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></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#log(java.lang.String)">log</A></B>(java.lang.String msg)</CODE>
<BR>
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> 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 message,
java.lang.Throwable throwable)</CODE>
<BR>
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> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../javax/servlet/ServletContext.html#removeAttribute(java.lang.String)">removeAttribute</A></B>(java.lang.String name)</CODE>
<BR>
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> 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 name,
java.lang.Object object)</CODE>
<BR>
Binds an object to a given attribute name in this servlet context.</TD>
</TR>
</TABLE>
<P>
<!-- ============ FIELD DETAIL =========== -->
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<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" title="interface in javax.servlet">ServletContext</A> <B>getContext</B>(java.lang.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 <A HREF="../../javax/servlet/RequestDispatcher.html" title="interface in javax.servlet"><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.
<P>
<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" title="interface in javax.servlet"><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.4 must have this method
return the integer 2.
<P>
<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.4 must have this method
return the integer 4.
<P>
<DD><DL>
<DT><B>Returns:</B><DD>4</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 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><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 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><CODE>path</CODE> - 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.<DT><B>Since:</B></DT>
<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 path)
throws java.net.MalformedURLException</PRE>
<DL>
<DD>Returns a URL to the resource that is mapped to a specified
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -