Skip to Main Content
Java Servlet Programming
book

Java Servlet Programming

by Jason Hunter
November 1998
Intermediate to advanced content levelIntermediate to advanced
526 pages
14h 38m
English
O'Reilly Media, Inc.
Content preview from Java Servlet Programming

Name

ServletContext

Synopsis

Interface Name: javax.servlet.ServletContext

Superinterface: None

Immediate Subinterfaces: None

Implemented By: None

Availability: Servlet API 1.0 and later

Description

The ServletContext interface defines a set of methods that can be used to communicate with the server in a non-request-specific manner. This includes finding path information, accessing other servlets running on the server, and writing to the server log file. Different virtual servers may return different servlet contexts.

Interface Declaration

public interface ServletContext {  
  // Methods
  public abstract Object getAttribute(String name);
  public abstract String getMimeType(String file);
  public abstract String getRealPath(String path);
  public abstract String getServerInfo();
  public abstract Servlet getServlet(String name) throws ServletException;
  public abstract Enumeration getServletNames();             // New in 2.0
  public abstract Enumeration getServlets();                 // Deprecated
  public abstract void log(Exception exception, String msg); // New in 2.0
  public abstract void log(String msg);
}

Methods

getAttribute()

public abstract Object getAttribute(String name)
Description

Returns the value of the named server attribute as an Object or null if the attribute does not exist. The attributes are server-dependent and allow web servers to provide servlets with information above and beyond that provided for by the base Servlet API. Attribute names should follow the same convention as package names. The package names java.*

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Servlet Programming, 2nd Edition

Java Servlet Programming, 2nd Edition

Jason Hunter, William Crawford

Publisher Resources

ISBN: 156592391XSupplemental ContentCatalog PageErrata