Name

application

Variable name:

application

Interface name:

javax.servlet.ServletContext

Extends:

None

Implemented by:

Internal container-dependent class

JSP Page type:

Available in both regular JSP pages and error pages

Description

The ServletContext provides resources shared within a web application. It holds attribute values representing the JSP application scope. An attribute value can be an instance of any valid Java class. The ServletContext also defines a set of methods that a JSP page or a servlet uses to communicate with its container; for example, to get the MIME type of a file, dispatch requests, or write to a log file. The web container is responsible for providing an implementation of the ServletContext interface.

Each ServletContext is assigned a specific URI path prefix within a web server. For example, a context could be responsible for all resources under http://www.mycorp.com/catalog. All requests that start with the /catalog request path, which is known as the context path, are routed to this servlet context.

Only one instance of a ServletContext may be available to the servlets and JSP pages in a web application. If the web application indicates that it is distributable, there must be only one instance of the ServletContext object in use per application in each Java Virtual Machine.

Methods

public Object getAttribute(String name)

Returns the servlet context attribute with the specified name, or null if there is no attribute by that name. Context attributes can be set ...

Get JavaServer Pages Pocket Reference 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.