Name
ServletContext
Synopsis
ServletContext
defines methods that allow a servlet to
interact with the host server. This includes reading server-specific
attributes, finding information about particular files located on the server,
and writing to the server log files. The
ServletContext
also allows
creation of RequestDispatcher
objects.
As of the Servlet 2.2 API, which introduced web applications, the
ServletContext
has been formalized as a programmatic
interface to a web application. Each web application has its own
ServletContext
, which is
shared by all of the servlets configured in the web application. The
servlets can use the setAttribute()
and
getAttribute()
methods of the
ServletContext
to share information throughout a web
application.
The getServlet()
,
getServletNames()
and
getServlets()
methods were
deprecated in versions 2.0 and 2.1 of the Servlet API, and have not
been directly replaced. Instead of accessing each other directly,
servlets should share information via the context attributes.
public interface ServletContext { // Property Accessor Methods (by property name) public abstract java.util.Enumeration getAttributeNames(); // 2.1 public abstract java.util.Enumeration getInitParameterNames( // 2.2 ); public abstract int getMajorVersion(); // 2.1 public abstract int getMinorVersion(); // 2.1 public abstract String getServerInfo(); public abstract String getServletContextName(); // 2.3 // Public Instance Methods public abstract Object getAttribute( String name); public ...
Get Java Enterprise in a Nutshell, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.