Top Description Inners Fields Constructors Methods
org.mortbay.jetty.handler

public Class ContextHandler

extends HandlerWrapper
implements Attributes, Graceful, CompleteHandler
Class Inheritance
All Implemented Interfaces
org.mortbay.jetty.handler.CompleteHandler, org.mortbay.jetty.Server.Graceful, org.mortbay.util.Attributes
Known Direct Subclasses
org.mortbay.jetty.handler.MovedContextHandler, org.mortbay.jetty.servlet.Context
Imports
java.io.File, .IOException, .InputStream, java.net.MalformedURLException, .URL, .URLClassLoader, java.util.Arrays, .Collections, .EnumSet, .Enumeration, .EventListener, .HashMap, .HashSet, .Locale, .Map, .Set, javax.servlet.DispatcherType, .RequestDispatcher, .Servlet, .ServletContext, .ServletContextAttributeEvent, .ServletContextAttributeListener, .ServletContextEvent, .ServletContextListener, .ServletException, .ServletRequestAttributeListener, .ServletRequestEvent, .ServletRequestListener, javax.servlet.http.HttpServletRequest, .HttpServletResponse, org.mortbay.io.Buffer, org.mortbay.jetty.Dispatcher, .Handler, .HandlerContainer, .HttpConnection, .HttpException, .MimeTypes, .Request, .Server, org.mortbay.log.Log, .Logger, org.mortbay.resource.Resource, org.mortbay.util.Attributes, .AttributesMap, .LazyList, .Loader, .URIUtil

ContextHandler. This handler wraps a call to handle by setting the context and servlet path, plus setting the context classloader.

If the context init parameter "org.mortbay.jetty.servlet.ManagedAttributes" is set to a coma separated list of names, then they are treated as context attribute names, which if set as attributes are passed to the servers Container so that they may be managed with JMX.

Author
gregw

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class

Field Summary

Modifier and TypeField and Description
private static ThreadLocal<ContextHandler.SContext>
private boolean
private boolean
private AttributesMap
private Resource
private ClassLoader
private boolean
private Set<String>
private Object
private AttributesMap
private Object
private String
private String
private ErrorHandler
private EventListener[]
private Map<String, String>
private Map<String, String>
private Logger
private Set<String>
private int
private MimeTypes
private Object
private Object
protected ContextHandler.SContext
private boolean
private String[]
private String[]
public static final String

Constructor Summary

AccessConstructor and Description
public
protected
public
ContextHandler(String contextPath)

public
ContextHandler(HandlerContainer parent, String contextPath)

Method Summary

Modifier and TypeMethod and Description
public void
addEventListener(EventListener listener)

Add a context event listeners.

public void
addLocaleEncoding(String locale, String encoding)

public void
public void
protected void
protected void
public boolean

Returns:

the allowNullPathInfo true if /context is not redirected to /context/
getAllowNullPathInfo
()

public Object
public Enumeration<E>
public Attributes

Returns:

Returns the attributes.
getAttributes
()

public Resource

Returns:

Returns the resourceBase.
getBaseResource
()

public ClassLoader

Returns:

Returns the classLoader.
getClassLoader
()

public String

Returns:

Returns the classLoader.
getClassPath
()

Make best effort to extract a file classpath from the context classloader

public String[]

Returns:

an array of connector names that this context will accept a request from.
getConnectorNames
()

public String

Returns:

Returns the _contextPath.
getContextPath
()

public static ContextHandler.SContext

Returns:

ServletContext implementation
getCurrentContext
()

Get the current ServletContext implementation.

public String
public ErrorHandler

Returns:

Returns the errorHandler.
getErrorHandler
()

public EventListener[]
public String[]
getHosts()

Deprecated
Get the hosts for the context.
public String
public Enumeration<E>
public Map<String, String>

Returns:

Returns the initParams.
getInitParams
()

public String

Returns:

a String representing the character encoding for the locale or null if none found.
getLocaleEncoding
(Locale
a Locale value
locale
)

Get the character encoding for a locale.

public Logger
public int
public MimeTypes

Returns:

Returns the mimeTypes.
getMimeTypes
()

public Resource
public String

Returns:

Returns the base resource as a string.
getResourceBase
()

public Set<String>
public ContextHandler.SContext
public String[]

Returns:

Array of virtual hosts that this context responds to. A null host name or empty array means any hostname is acceptable. Host names may be String representation of IP addresses. Host names may start with '*.' to wildcard one level of names.
getVirtualHosts
()

Get the virtual hosts for the context.

public String[]

Returns:

The names of the files which the server should consider to be welcome files in this context.
getWelcomeFiles
()

public void
handle(String
The target of the request - either a URI or a name.
target
,
HttpServletRequest
The request either as the Request object or a wrapper of that request. The HttpConnection#getCurrentConnection() method can be used access the Request object if required.
request
,
HttpServletResponse
The response as the Response object or a wrapper of that request. The HttpConnection#getCurrentConnection() method can be used access the Response object if required.
response
,
int
The dispatch mode: REQUEST, FORWARD, INCLUDE, ERROR
dispatch
)

Overrides org.mortbay.jetty.handler.HandlerWrapper.handle.

Implements org.mortbay.jetty.Handler.handle.

Handle a request.
public boolean

Returns:

True if alias checking is performed on resources.
isAliases
()

public boolean

Returns:

True if URLs are compacted to replace multiple '/'s with a single '/'
isCompactPath
()

protected boolean
isProtectedTarget(String target)

Check the target.

public boolean

Returns:

true if this context is accepting new requests
isShutdown
()

public synchronized Class<?>
loadClass(String className)

public Resource
newResource(URL url)

Convert URL to Resource wrapper for Resource#newResource(URL) enables extensions to provide alternate resource implementations.

public Resource
newResource(String url)

Convert URL to Resource wrapper for Resource#newResource(String) enables extensions to provide alternate resource implementations.

private String
public void
public void
setAliases(boolean
alias checking performed on resources.
aliases
)

public void
setAllowNullPathInfo(boolean
true if /context is not redirected to /context/
allowNullPathInfo
)

public void
public void
setAttributes(Attributes
The attributes to set.
attributes
)

public void
setBaseResource(Resource
The resourceBase to set.
base
)

public void
setClassLoader(ClassLoader
The classLoader to set.
classLoader
)

public void
setCompactPath(boolean
True if URLs are compacted to replace multiple '/'s with a single '/'
compactPath
)

public void
setConnectorNames(String[]
If non null, an array of connector names that this context will accept a request from.
connectors
)

Set the names of accepted connectors.

public void
setContextPath(String
The _contextPath to set.
contextPath
)

public void
setDisplayName(String
The servletContextName to set.
servletContextName
)

public void
setErrorHandler(ErrorHandler
The errorHandler to set.
errorHandler
)

public void
setEventListeners(EventListener[] eventListeners)

Set the context event listeners.

public void
public void
setInitParams(Map<String, String>
The initParams to set.
initParams
)

public void
setLogger(Logger logger)

private void
public void
setMaxFormContentSize(int maxSize)

public void
setMimeTypes(MimeTypes
The mimeTypes to set.
mimeTypes
)

public void
setResourceBase(String
The base resource as a string.
resourceBase
)

public void
public void
setShutdown(boolean
true if this context is accepting new requests
shutdown
)

Implements org.mortbay.jetty.Server.Graceful.setShutdown.

Set shutdown status.
public void
setVirtualHosts(String[]
Array of virtual hosts that this context responds to. A null host name or null/empty array means any hostname is acceptable. Host names may be String representation of IP addresses. Host names may start with '*.' to wildcard one level of names.
vhosts
)

Set the virtual hosts for the context.

public void
protected void
public String
toString()

Overrides org.mortbay.jetty.handler.AbstractHandler.toString.

Returns a string representation of the object.
Inherited from org.mortbay.jetty.handler.HandlerWrapper:
addHandlerexpandChildrengetHandlerremoveHandlersetHandler

Field Detail

__contextback to summary
private static ThreadLocal<ContextHandler.SContext> __context
_aliasesback to summary
private boolean _aliases
_allowNullPathInfoback to summary
private boolean _allowNullPathInfo
_attributesback to summary
private AttributesMap _attributes
_baseResourceback to summary
private Resource _baseResource
_classLoaderback to summary
private ClassLoader _classLoader
_compactPathback to summary
private boolean _compactPath
_connectorsback to summary
private Set<String> _connectors
_contextAttributeListenersback to summary
private Object _contextAttributeListeners
_contextAttributesback to summary
private AttributesMap _contextAttributes
_contextListenersback to summary
private Object _contextListeners
_contextPathback to summary
private String _contextPath
_displayNameback to summary
private String _displayName
_errorHandlerback to summary
private ErrorHandler _errorHandler
_eventListenersback to summary
private EventListener[] _eventListeners
_initParamsback to summary
private Map<String, String> _initParams
_localeEncodingMapback to summary
private Map<String, String> _localeEncodingMap
_loggerback to summary
private Logger _logger
_managedAttributesback to summary
private Set<String> _managedAttributes
_maxFormContentSizeback to summary
private int _maxFormContentSize
_mimeTypesback to summary
private MimeTypes _mimeTypes
_requestAttributeListenersback to summary
private Object _requestAttributeListeners
_requestListenersback to summary
private Object _requestListeners
_scontextback to summary
protected ContextHandler.SContext _scontext
_shutdownback to summary
private boolean _shutdown
_vhostsback to summary
private String[] _vhosts
_welcomeFilesback to summary
private String[] _welcomeFiles
MANAGED_ATTRIBUTESback to summary
public static final String MANAGED_ATTRIBUTES

Constructor Detail

ContextHandlerback to summary
public ContextHandler()
ContextHandlerback to summary
protected ContextHandler(ContextHandler.SContext context)
ContextHandlerback to summary
public ContextHandler(String contextPath)
ContextHandlerback to summary
public ContextHandler(HandlerContainer parent, String contextPath)

Method Detail

addEventListenerback to summary
public void addEventListener(EventListener listener)

Add a context event listeners.

See Also
ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener
addLocaleEncodingback to summary
public void addLocaleEncoding(String locale, String encoding)
clearAttributesback to summary
public void clearAttributes()

Implements org.mortbay.util.Attributes.clearAttributes.

completeback to summary
public void complete(Request request)

Implements org.mortbay.jetty.handler.CompleteHandler.complete.

doStartback to summary
protected void doStart() throws Exception

Overrides org.mortbay.jetty.handler.HandlerWrapper.doStart.

doStopback to summary
protected void doStop() throws Exception

Overrides org.mortbay.jetty.handler.HandlerWrapper.doStop.

getAllowNullPathInfoback to summary
public boolean getAllowNullPathInfo()
Returns:boolean

the allowNullPathInfo true if /context is not redirected to /context/

getAttributeback to summary
public Object getAttribute(String name)

Implements org.mortbay.util.Attributes.getAttribute.

getAttributeNamesback to summary
public Enumeration<E> getAttributeNames()

Implements org.mortbay.util.Attributes.getAttributeNames.

Annotations
@SuppressWarnings:unchecked
getAttributesback to summary
public Attributes getAttributes()
Returns:Attributes

Returns the attributes.

getBaseResourceback to summary
public Resource getBaseResource()
Returns:Resource

Returns the resourceBase.

getClassLoaderback to summary
public ClassLoader getClassLoader()
Returns:ClassLoader

Returns the classLoader.

getClassPathback to summary
public String getClassPath()

Make best effort to extract a file classpath from the context classloader

Returns:String

Returns the classLoader.

getConnectorNamesback to summary
public String[] getConnectorNames()
Returns:String[]

an array of connector names that this context will accept a request from.

getContextPathback to summary
public String getContextPath()
Returns:String

Returns the _contextPath.

getCurrentContextback to summary
public static ContextHandler.SContext getCurrentContext()

Get the current ServletContext implementation. This call is only valid during a call to doStart and is available to nested handlers to access the context.

Returns:ContextHandler.SContext

ServletContext implementation

getDisplayNameback to summary
public String getDisplayName()
getErrorHandlerback to summary
public ErrorHandler getErrorHandler()
Returns:ErrorHandler

Returns the errorHandler.

getEventListenersback to summary
public EventListener[] getEventListeners()
getHostsback to summary
public String[] getHosts()

Deprecated

Get the hosts for the context.

getInitParameterback to summary
public String getInitParameter(String name)
getInitParameterNamesback to summary
public Enumeration<E> getInitParameterNames()
Annotations
@SuppressWarnings:unchecked
getInitParamsback to summary
public Map<String, String> getInitParams()
Returns:Map<String, String>

Returns the initParams.

getLocaleEncodingback to summary
public String getLocaleEncoding(Locale locale)

Get the character encoding for a locale. The full locale name is first looked up in the map of encodings. If no encoding is found, then the locale language is looked up.

Parameters
locale:Locale

a Locale value

Returns:String

a String representing the character encoding for the locale or null if none found.

getLoggerback to summary
public Logger getLogger()
getMaxFormContentSizeback to summary
public int getMaxFormContentSize()
getMimeTypesback to summary
public MimeTypes getMimeTypes()
Returns:MimeTypes

Returns the mimeTypes.

getResourceback to summary
public Resource getResource(String path) throws MalformedURLException
getResourceBaseback to summary
public String getResourceBase()
Returns:String

Returns the base resource as a string.

getResourcePathsback to summary
public Set<String> getResourcePaths(String path)
getServletContextback to summary
public ContextHandler.SContext getServletContext()
getVirtualHostsback to summary
public String[] getVirtualHosts()

Get the virtual hosts for the context. Only requests that have a matching host header or fully qualified URL will be passed to that context with a virtual host name. A context with no virtual host names or a null virtual host name is available to all requests that are not served by a context with a matching virtual host name.

Returns:String[]

Array of virtual hosts that this context responds to. A null host name or empty array means any hostname is acceptable. Host names may be String representation of IP addresses. Host names may start with '*.' to wildcard one level of names.

getWelcomeFilesback to summary
public String[] getWelcomeFiles()
Returns:String[]

The names of the files which the server should consider to be welcome files in this context.

See Also
The Servlet Specification, setWelcomeFiles
handleback to summary
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException

Overrides org.mortbay.jetty.handler.HandlerWrapper.handle.

Implements org.mortbay.jetty.Handler.handle.

Doc from org.mortbay.jetty.Handler.handle.

Handle a request.

Parameters
target:String

The target of the request - either a URI or a name.

request:HttpServletRequest

The request either as the Request object or a wrapper of that request. The HttpConnection#getCurrentConnection() method can be used access the Request object if required.

response:HttpServletResponse

The response as the Response object or a wrapper of that request. The HttpConnection#getCurrentConnection() method can be used access the Response object if required.

dispatch:int

The dispatch mode: REQUEST, FORWARD, INCLUDE, ERROR

isAliasesback to summary
public boolean isAliases()
Returns:boolean

True if alias checking is performed on resources.

isCompactPathback to summary
public boolean isCompactPath()
Returns:boolean

True if URLs are compacted to replace multiple '/'s with a single '/'

isProtectedTargetback to summary
protected boolean isProtectedTarget(String target)

Check the target. Called by handle(String, HttpServletRequest, HttpServletResponse, int) when a target within a context is determined. If the target is protected, 404 is returned. The default implementation always returns false.

See Also
org.mortbay.jetty.webapp.WebAppContext#isProtectedTarget(String)
isShutdownback to summary
public boolean isShutdown()
Returns:boolean

true if this context is accepting new requests

loadClassback to summary
public synchronized Class<?> loadClass(String className) throws ClassNotFoundException
newResourceback to summary
public Resource newResource(URL url) throws IOException

Convert URL to Resource wrapper for Resource#newResource(URL) enables extensions to provide alternate resource implementations.

newResourceback to summary
public Resource newResource(String url) throws IOException

Convert URL to Resource wrapper for Resource#newResource(String) enables extensions to provide alternate resource implementations.

normalizeHostnameback to summary
private String normalizeHostname(String host)
removeAttributeback to summary
public void removeAttribute(String name)

Implements org.mortbay.util.Attributes.removeAttribute.

setAliasesback to summary
public void setAliases(boolean aliases)
Parameters
aliases:boolean

alias checking performed on resources.

setAllowNullPathInfoback to summary
public void setAllowNullPathInfo(boolean allowNullPathInfo)
Parameters
allowNullPathInfo:boolean

true if /context is not redirected to /context/

setAttributeback to summary
public void setAttribute(String name, Object value)

Implements org.mortbay.util.Attributes.setAttribute.

setAttributesback to summary
public void setAttributes(Attributes attributes)
Parameters
attributes:Attributes

The attributes to set.

setBaseResourceback to summary
public void setBaseResource(Resource base)
Parameters
base:Resource

The resourceBase to set.

setClassLoaderback to summary
public void setClassLoader(ClassLoader classLoader)
Parameters
classLoader:ClassLoader

The classLoader to set.

setCompactPathback to summary
public void setCompactPath(boolean compactPath)
Parameters
compactPath:boolean

True if URLs are compacted to replace multiple '/'s with a single '/'

setConnectorNamesback to summary
public void setConnectorNames(String[] connectors)

Set the names of accepted connectors. Names are either "host:port" or a specific configured name for a connector.

Parameters
connectors:String[]

If non null, an array of connector names that this context will accept a request from.

setContextPathback to summary
public void setContextPath(String contextPath)
Parameters
contextPath:String

The _contextPath to set.

setDisplayNameback to summary
public void setDisplayName(String servletContextName)
Parameters
servletContextName:String

The servletContextName to set.

setErrorHandlerback to summary
public void setErrorHandler(ErrorHandler errorHandler)
Parameters
errorHandler:ErrorHandler

The errorHandler to set.

setEventListenersback to summary
public void setEventListeners(EventListener[] eventListeners)

Set the context event listeners.

See Also
ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener
setHostsback to summary
public void setHosts(String[] hosts)
setInitParamsback to summary
public void setInitParams(Map<String, String> initParams)
Parameters
initParams:Map<String, String>

The initParams to set.

setLoggerback to summary
public void setLogger(Logger logger)
setManagedAttributeback to summary
private void setManagedAttribute(String name, Object value)
setMaxFormContentSizeback to summary
public void setMaxFormContentSize(int maxSize)
setMimeTypesback to summary
public void setMimeTypes(MimeTypes mimeTypes)
Parameters
mimeTypes:MimeTypes

The mimeTypes to set.

setResourceBaseback to summary
public void setResourceBase(String resourceBase)
Parameters
resourceBase:String

The base resource as a string.

setServerback to summary
public void setServer(Server server)

Overrides org.mortbay.jetty.handler.HandlerWrapper.setServer.

Implements org.mortbay.jetty.Handler.setServer.

setShutdownback to summary
public void setShutdown(boolean shutdown)

Implements org.mortbay.jetty.Server.Graceful.setShutdown.

Set shutdown status. This field allows for graceful shutdown of a context. A started context may be put into non accepting state so that existing requests can complete, but no new requests are accepted.

Parameters
shutdown:boolean

true if this context is accepting new requests

setVirtualHostsback to summary
public void setVirtualHosts(String[] vhosts)

Set the virtual hosts for the context. Only requests that have a matching host header or fully qualified URL will be passed to that context with a virtual host name. A context with no virtual host names or a null virtual host name is available to all requests that are not served by a context with a matching virtual host name.

Parameters
vhosts:String[]

Array of virtual hosts that this context responds to. A null host name or null/empty array means any hostname is acceptable. Host names may be String representation of IP addresses. Host names may start with '*.' to wildcard one level of names.

setWelcomeFilesback to summary
public void setWelcomeFiles(String[] files)
startContextback to summary
protected void startContext() throws Exception
toStringback to summary
public String toString()

Overrides org.mortbay.jetty.handler.AbstractHandler.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

org.mortbay.jetty.handler back to summary

public Class ContextHandler.SContext

extends Object
implements ServletContext
Class Inheritance
All Implemented Interfaces
javax.servlet.ServletContext
Known Direct Subclasses
org.mortbay.jetty.servlet.Context.SContext

Context.

Implements javax.servlet.ServletContext from the javax.servlet package.

Author
gregw

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
addFilter(String filterName, String description, String className, Map<String, String> initParameters)

public void
addFilterMapping(String filterName, String[] urlPatterns, String[] servletNames, EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter)

public void
addServlet(String servletName, String description, String className, Map<String, String> initParameters, int loadOnStartup)

public void
addServletMapping(String servletName, String[] urlPatterns)

public synchronized Object
getAttribute(String
a String specifying the name of the attribute
name
)

Implements javax.servlet.ServletContext.getAttribute.

Returns the servlet container attribute with the given name, or null if there is no attribute by that name.
public synchronized Enumeration<E>
getAttributeNames()

Implements javax.servlet.ServletContext.getAttributeNames.

Returns an Enumeration containing the attribute names available within this ServletContext.
public ServletContext
getContext(String
a String specifying the context path of another web application in the container.
uripath
)

Implements javax.servlet.ServletContext.getContext.

Returns a ServletContext object that corresponds to a specified URL on the server.
public ContextHandler
public String

Returns:

Returns the _contextPath.
getContextPath
()

Implements javax.servlet.ServletContext.getContextPath.

Returns the context path of the web application.
public String
getInitParameter(String
a String containing the name of the parameter whose value is requested
name
)

Implements javax.servlet.ServletContext.getInitParameter.

Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.
public Enumeration<E>
getInitParameterNames()

Implements javax.servlet.ServletContext.getInitParameterNames.

Returns the names of the context's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the context has no initialization parameters.
public int
getMajorVersion()

Implements javax.servlet.ServletContext.getMajorVersion.

Returns the major version of the Servlet API that this servlet container supports.
public String
getMimeType(String
a String specifying the name of a file
file
)

Implements javax.servlet.ServletContext.getMimeType.

Returns the MIME type of the specified file, or null if the MIME type is not known.
public int
getMinorVersion()

Implements javax.servlet.ServletContext.getMinorVersion.

Returns the minor version of the Servlet API that this servlet container supports.
public RequestDispatcher
getNamedDispatcher(String
a String specifying the name of a servlet to wrap
name
)

Implements javax.servlet.ServletContext.getNamedDispatcher.

Returns a RequestDispatcher object that acts as a wrapper for the named servlet.
public String
getRealPath(String
the virtual path to be translated to a real path
path
)

Implements javax.servlet.ServletContext.getRealPath.

Gets the real path corresponding to the given virtual path.
public RequestDispatcher
getRequestDispatcher(String
a String specifying the pathname to the resource
uriInContext
)

Implements javax.servlet.ServletContext.getRequestDispatcher.

Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.
public URL
getResource(String
a String specifying the path to the resource
path
)

Implements javax.servlet.ServletContext.getResource.

Returns a URL to the resource that is mapped to the given path.
public InputStream
getResourceAsStream(String
a String specifying the path to the resource
path
)

Implements javax.servlet.ServletContext.getResourceAsStream.

Returns the resource located at the named path as an InputStream object.
public Set<E>
getResourcePaths(String
the partial path used to match the resources, which must start with a /
path
)

Implements javax.servlet.ServletContext.getResourcePaths.

Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument.
public String
getServerInfo()

Implements javax.servlet.ServletContext.getServerInfo.

Returns the name and version of the servlet container on which the servlet is running.
public Servlet
public String
getServletContextName()

Implements javax.servlet.ServletContext.getServletContextName.

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.
public Enumeration<E>
public Enumeration<E>
public void
log(Exception
the Exception error
exception
,
String
a String that describes the exception
msg
)

Implements javax.servlet.ServletContext.log.

public void
log(String
a String specifying the message to be written to the log file
msg
)

Implements javax.servlet.ServletContext.log.

Writes the specified message to a servlet log file, usually an event log.
public void
log(String
a String that describes the error or exception
message
,
Throwable
the Throwable error or exception
throwable
)

Implements javax.servlet.ServletContext.log.

Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file.
public synchronized void
removeAttribute(String
a String specifying the name of the attribute to be removed
name
)

Implements javax.servlet.ServletContext.removeAttribute.

Removes the attribute with the given name from this ServletContext.
public synchronized void
setAttribute(String
a String specifying the name of the attribute
name
,
Object
an Object representing the attribute to be bound
value
)

Implements javax.servlet.ServletContext.setAttribute.

Binds an object to a given attribute name in this ServletContext.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Constructor Detail

SContextback to summary
protected SContext()

Method Detail

addFilterback to summary
public void addFilter(String filterName, String description, String className, Map<String, String> initParameters)
addFilterMappingback to summary
public void addFilterMapping(String filterName, String[] urlPatterns, String[] servletNames, EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter)
addServletback to summary
public void addServlet(String servletName, String description, String className, Map<String, String> initParameters, int loadOnStartup)
addServletMappingback to summary
public void addServletMapping(String servletName, String[] urlPatterns)
getAttributeback to summary
public synchronized Object getAttribute(String name)

Implements javax.servlet.ServletContext.getAttribute.

Doc from javax.servlet.ServletContext.getAttribute.

Returns the servlet container attribute with the given name, or null if there is no attribute by that name.

An attribute allows a servlet container to give the servlet additional information not already provided by this interface. See your server documentation for information about its attributes. A list of supported attributes can be retrieved using getAttributeNames.

The attribute is returned as a java.lang.Object or some subclass.

Attribute names should follow the same convention as package names. The Java Servlet API specification reserves names matching java.*, javax.*, and sun.*.

Parameters
name:String

a String specifying the name of the attribute

Returns:Object

an Object containing the value of the attribute, or null if no attribute exists matching the given name.

getAttributeNamesback to summary
public synchronized Enumeration<E> getAttributeNames()

Implements javax.servlet.ServletContext.getAttributeNames.

Doc from javax.servlet.ServletContext.getAttributeNames.

Returns an Enumeration containing the attribute names available within this ServletContext.

Use the getAttribute method with an attribute name to get the value of an attribute.

Returns:Enumeration<E>

an Enumeration of attribute names

Annotations
@SuppressWarnings:unchecked
getContextback to summary
public ServletContext getContext(String uripath)

Implements javax.servlet.ServletContext.getContext.

Doc from javax.servlet.ServletContext.getContext.

Returns a ServletContext object that corresponds to a specified URL on the server.

This method allows servlets to gain access to the context for various parts of the server, and as needed obtain 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.

In a security conscious environment, the servlet container may return null for a given URL.

Parameters
uripath:String

a String specifying the context path of another web application in the container.

Returns:ServletContext

the ServletContext object that corresponds to the named URL, or null if either none exists or the container wishes to restrict this access.

getContextHandlerback to summary
public ContextHandler getContextHandler()
getContextPathback to summary
public String getContextPath()

Implements javax.servlet.ServletContext.getContextPath.

Doc from javax.servlet.ServletContext.getContextPath.

Returns the context path of the web application.

The context path is the portion of the request URI that is used to select the context of the request. The context path always comes first in a request URI. If this context is the "root" context rooted at the base of the Web server's URL name space, this path will be an empty string. Otherwise, if the context is not rooted at the root of the server's name space, the path starts with a / character but does not end with a / character.

It is possible that a servlet container may match a context by more than one context path. In such cases the javax.servlet.http.HttpServletRequest#getContextPath() will return the actual context path used by the request and it may differ from the path returned by this method. The context path returned by this method should be considered as the prime or preferred context path of the application.

Returns:String

Returns the _contextPath.

getInitParameterback to summary
public String getInitParameter(String name)

Implements javax.servlet.ServletContext.getInitParameter.

Doc from javax.servlet.ServletContext.getInitParameter.

Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.

This method can make available configuration information useful to an entire web application. For example, it can provide a webmaster's email address or the name of a system that holds critical data.

Parameters
name:String

a String containing the name of the parameter whose value is requested

Returns:String

a String containing the value of the context's initialization parameter, or null if the context's initialization parameter does not exist.

getInitParameterNamesback to summary
public Enumeration<E> getInitParameterNames()

Implements javax.servlet.ServletContext.getInitParameterNames.

Doc from javax.servlet.ServletContext.getInitParameterNames.

Returns the names of the context's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the context has no initialization parameters.

Returns:Enumeration<E>

an Enumeration of String objects containing the names of the context's initialization parameters

Annotations
@SuppressWarnings:unchecked
getMajorVersionback to summary
public int getMajorVersion()

Implements javax.servlet.ServletContext.getMajorVersion.

Doc from javax.servlet.ServletContext.getMajorVersion.

Returns the major version of the Servlet API that this servlet container supports. All implementations that comply with Version 4.0 must have this method return the integer 4.

Returns:int

4

getMimeTypeback to summary
public String getMimeType(String file)

Implements javax.servlet.ServletContext.getMimeType.

Doc from javax.servlet.ServletContext.getMimeType.

Returns the MIME type of the specified file, or null 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 include text/html and image/gif.

Parameters
file:String

a String specifying the name of a file

Returns:String

a String specifying the file's MIME type

getMinorVersionback to summary
public int getMinorVersion()

Implements javax.servlet.ServletContext.getMinorVersion.

Doc from javax.servlet.ServletContext.getMinorVersion.

Returns the minor version of the Servlet API that this servlet container supports. All implementations that comply with Version 4.0 must have this method return the integer 0.

Returns:int

0

getNamedDispatcherback to summary
public RequestDispatcher getNamedDispatcher(String name)

Implements javax.servlet.ServletContext.getNamedDispatcher.

Doc from javax.servlet.ServletContext.getNamedDispatcher.

Returns a RequestDispatcher object that acts as a wrapper for the named servlet.

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 ServletConfig#getServletName.

This method returns null if the ServletContext cannot return a RequestDispatcher for any reason.

Parameters
name:String

a String specifying the name of a servlet to wrap

Returns:RequestDispatcher

a RequestDispatcher object that acts as a wrapper for the named servlet, or null if the ServletContext cannot return a RequestDispatcher

getRealPathback to summary
public String getRealPath(String path)

Implements javax.servlet.ServletContext.getRealPath.

Doc from javax.servlet.ServletContext.getRealPath.

Gets the real path corresponding to the given virtual path.

For example, if path is equal to /index.html, this method will return the absolute file path on the server's filesystem to which a request of the form http://<host>:<port>/<contextPath>/index.html would be mapped, where <contextPath> corresponds to the context path of this ServletContext.

The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators.

Resources inside the /META-INF/resources directories of JAR files bundled in the application's /WEB-INF/lib directory must be considered only if the container has unpacked them from their containing JAR file, in which case the path to the unpacked location must be returned.

This method returns null if the servlet container is unable to translate the given virtual path to a real path.

Parameters
path:String

the virtual path to be translated to a real path

Returns:String

the real path, or null if the translation cannot be performed

getRequestDispatcherback to summary
public RequestDispatcher getRequestDispatcher(String uriInContext)

Implements javax.servlet.ServletContext.getRequestDispatcher.

Doc from javax.servlet.ServletContext.getRequestDispatcher.

Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher 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.

The pathname must begin with a / and is interpreted as relative to the current context root. Use getContext to obtain a RequestDispatcher for resources in foreign contexts.

This method returns null if the ServletContext cannot return a RequestDispatcher.

Parameters
uriInContext:String

a String specifying the pathname to the resource

Returns:RequestDispatcher

a RequestDispatcher object that acts as a wrapper for the resource at the specified path, or null if the ServletContext cannot return a RequestDispatcher

getResourceback to summary
public URL getResource(String path) throws MalformedURLException

Implements javax.servlet.ServletContext.getResource.

Doc from javax.servlet.ServletContext.getResource.

Returns a URL to the resource that is mapped to the given path.

The path must begin with a / and is interpreted as relative to the current context root, or relative to the /META-INF/resources directory of a JAR file inside the web application's /WEB-INF/lib directory. This method will first search the document root of the web application for the requested resource, before searching any of the JAR files inside /WEB-INF/lib. The order in which the JAR files inside /WEB-INF/lib are searched is undefined.

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 .war file.

The servlet container must implement the URL handlers and URLConnection objects that are necessary to access the resource.

This method returns null if no resource is mapped to the pathname.

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

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

This method has a different purpose than java.lang.Class.getResource, which looks up resources based on a class loader. This method does not use class loaders.

Parameters
path:String

a String specifying the path to the resource

Returns:URL

the resource located at the named path, or null if there is no resource at that path

Exceptions
MalformedURLException:
if the pathname is not given in the correct form
getResourceAsStreamback to summary
public InputStream getResourceAsStream(String path)

Implements javax.servlet.ServletContext.getResourceAsStream.

Doc from javax.servlet.ServletContext.getResourceAsStream.

Returns the resource located at the named path as an InputStream object.

The data in the InputStream can be of any type or length. The path must be specified according to the rules given in getResource. This method returns null if no resource exists at the specified path.

Meta-information such as content length and content type that is available via getResource method is lost when using this method.

The servlet container must implement the URL handlers and URLConnection objects necessary to access the resource.

This method is different from java.lang.Class.getResourceAsStream, 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.

Parameters
path:String

a String specifying the path to the resource

Returns:InputStream

the InputStream returned to the servlet, or null if no resource exists at the specified path

getResourcePathsback to summary
public Set<E> getResourcePaths(String path)

Implements javax.servlet.ServletContext.getResourcePaths.

Doc from javax.servlet.ServletContext.getResourcePaths.

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, or relative to the /META-INF/resources directory of a JAR file inside the web application's /WEB-INF/lib directory, and have a leading /.

The returned set is not backed by the ServletContext object, so changes in the returned set are not reflected in the ServletContext object, and vice-versa.

For example, for a web application containing:

/welcome.html
  /catalog/index.html
  /catalog/products.html
  /catalog/offers/books.html
  /catalog/offers/music.html
  /customer/login.jsp
  /WEB-INF/web.xml
  /WEB-INF/classes/com.acme.OrderServlet.class
  /WEB-INF/lib/catalog.jar!/META-INF/resources/catalog/moreOffers/books.html
getResourcePaths("/") would return {"/welcome.html", "/catalog/", "/customer/", "/WEB-INF/"}, and getResourcePaths("/catalog/") would return {"/catalog/index.html", "/catalog/products.html", "/catalog/offers/", "/catalog/moreOffers/"}.
Parameters
path:String

the partial path used to match the resources, which must start with a /

Returns:Set<E>

a Set containing the directory listing, or null if there are no resources in the web application whose path begins with the supplied path.

getServerInfoback to summary
public String getServerInfo()

Implements javax.servlet.ServletContext.getServerInfo.

Doc from javax.servlet.ServletContext.getServerInfo.

Returns the name and version of the servlet container on which the servlet is running.

The form of the returned string is servername/versionnumber. For example, the JavaServer Web Development Kit may return the string JavaServer Web Dev Kit/1.0.

The servlet container may return other optional information after the primary string in parentheses, for example, JavaServer Web Dev Kit/1.0 (JDK 1.1.6; Windows NT 4.0 x86).

Returns:String

a String containing at least the servlet container name and version number

getServletback to summary
public Servlet getServlet(String name) throws ServletException

Implements javax.servlet.ServletContext.getServlet.

Parameters
name:String

Doc from javax.servlet.ServletContext.getServlet.

the servlet name

Returns:Servlet

Doc from javax.servlet.ServletContext.getServlet.

the javax.servlet.Servlet Servlet with the given name

Exceptions
ServletException:

Doc from javax.servlet.ServletContext.getServlet.

if an exception has occurred that interfaces with servlet's normal operation

getServletContextNameback to summary
public String getServletContextName()

Implements javax.servlet.ServletContext.getServletContextName.

Doc from javax.servlet.ServletContext.getServletContextName.

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.

Returns:String

The name of the web application or null if no name has been declared in the deployment descriptor.

getServletNamesback to summary
public Enumeration<E> getServletNames()

Implements javax.servlet.ServletContext.getServletNames.

Returns:Enumeration<E>

Doc from javax.servlet.ServletContext.getServletNames.

an Enumeration of javax.servlet.Servlet Servlet names

Annotations
@SuppressWarnings:unchecked
getServletsback to summary
public Enumeration<E> getServlets()

Implements javax.servlet.ServletContext.getServlets.

Returns:Enumeration<E>

Doc from javax.servlet.ServletContext.getServlets.

an Enumeration of javax.servlet.Servlet Servlet

Annotations
@SuppressWarnings:unchecked
logback to summary
public void log(Exception exception, String msg)

Implements javax.servlet.ServletContext.log.

Parameters
exception:Exception

Doc from javax.servlet.ServletContext.log.

the Exception error

msg:String

Doc from javax.servlet.ServletContext.log.

a String that describes the exception

logback to summary
public void log(String msg)

Implements javax.servlet.ServletContext.log.

Doc from javax.servlet.ServletContext.log.

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.

Parameters
msg:String

a String specifying the message to be written to the log file

logback to summary
public void log(String message, Throwable throwable)

Implements javax.servlet.ServletContext.log.

Doc from javax.servlet.ServletContext.log.

Writes an explanatory message and a stack trace for a given Throwable 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.

Parameters
message:String

a String that describes the error or exception

throwable:Throwable

the Throwable error or exception

removeAttributeback to summary
public synchronized void removeAttribute(String name)

Implements javax.servlet.ServletContext.removeAttribute.

Doc from javax.servlet.ServletContext.removeAttribute.

Removes the attribute with the given name from this ServletContext. After removal, subsequent calls to getAttribute to retrieve the attribute's value will return null.

If listeners are configured on the ServletContext the container notifies them accordingly.

Parameters
name:String

a String specifying the name of the attribute to be removed

setAttributeback to summary
public synchronized void setAttribute(String name, Object value)

Implements javax.servlet.ServletContext.setAttribute.

Doc from javax.servlet.ServletContext.setAttribute.

Binds an object to a given attribute name in this ServletContext. If the name specified is already used for an attribute, this method will replace the attribute with the new to the new attribute.

If listeners are configured on the ServletContext the container notifies them accordingly.

If a null value is passed, the effect is the same as calling removeAttribute().

Attribute names should follow the same convention as package names. The Java Servlet API specification reserves names matching java.*, javax.*, and sun.*.

Parameters
name:String

a String specifying the name of the attribute

value:Object

an Object representing the attribute to be bound

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object