org.mortbay.jetty.servlet
Class Context

java.lang.Object
  |
  +--org.mortbay.jetty.servlet.Context
All Implemented Interfaces:
HttpSessionContext, ServletContext

public class Context
extends java.lang.Object
implements ServletContext, HttpSessionContext

Jetty Servlet Context.

Version:
$Id: Context.java,v 1.6 2001/11/01 05:49:22 gregwilkins Exp $
Author:
Greg Wilkins

Field Summary
static int __distantFuture
           
static java.lang.String __SessionId
           
static java.lang.String __SessionUrlPrefix
           
 
Method Summary
static void access(HttpSession session)
           
 java.lang.Object getAttribute(java.lang.String name)
          Get context attribute.
 java.util.Enumeration getAttributeNames()
          Get context attribute names.
 ServletContext getContext(java.lang.String uri)
          Returns a ServletContext object that corresponds to a specified URL on the server.
 java.lang.String getContextPath()
           
 java.util.Enumeration getIds()
          Deprecated. From HttpSessionContext
 java.lang.String getInitParameter(java.lang.String param)
          Get context init parameter.
 java.util.Enumeration getInitParameterNames()
          Get context init parameter names.
 int getMajorVersion()
          Returns the major version of the Java Servlet API that this servlet container supports.
 java.lang.String getMimeType(java.lang.String file)
          Returns the MIME type of the specified file, or null if the MIME type is not known.
 int getMinorVersion()
          Returns the minor version of the Servlet API that this servlet container supports.
 RequestDispatcher getNamedDispatcher(java.lang.String name)
          Returns a RequestDispatcher object that acts as a wrapper for the named servlet.
 java.lang.String getRealPath(java.lang.String path)
          Returns a String containing the real path for a given virtual path.
 RequestDispatcher getRequestDispatcher(java.lang.String uriInContext)
          Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.
 java.net.URL getResource(java.lang.String uriInContext)
          Get a Resource.
 java.io.InputStream getResourceAsStream(java.lang.String uriInContext)
          Returns the resource located at the named path as an InputStream object.
 java.lang.String getServerInfo()
          Returns the name and version of the servlet container on which the servlet is running.
 Servlet getServlet(java.lang.String name)
          Deprecated.  
 java.util.Enumeration getServletNames()
          Deprecated.  
 java.util.Enumeration getServlets()
          Deprecated.  
 HttpSession getSession(java.lang.String id)
          Deprecated. From HttpSessionContext
static boolean isValid(HttpSession session)
           
 void log(java.lang.Exception e, java.lang.String msg)
           
 void log(java.lang.String msg)
          Servlet Log.
 void log(java.lang.String msg, java.lang.Throwable th)
          Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file.
 HttpSession newSession()
           
 void removeAttribute(java.lang.String name)
          Remove context attribute.
 int sessionCount()
           
 void setAttribute(java.lang.String name, java.lang.Object value)
          Set context attribute names.
 void setSessionTimeout(int timeoutMinutes)
          Set the default session timeout.
 void stop()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

__SessionId

public static final java.lang.String __SessionId

__SessionUrlPrefix

public static final java.lang.String __SessionUrlPrefix

__distantFuture

public static final int __distantFuture
Method Detail

getContextPath

public java.lang.String getContextPath()

getContext

public ServletContext getContext(java.lang.String uri)
Description copied from interface: ServletContext
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 absolute (beginning with "/") and is interpreted based on the server's document root.

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

Specified by:
getContext in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
uripath - a String specifying the absolute URL of a resource on the server
Returns:
the ServletContext object that corresponds to the named URL
See Also:
RequestDispatcher

getMajorVersion

public int getMajorVersion()
Description copied from interface: ServletContext
Returns the major version of the Java Servlet API that this servlet container supports. All implementations that comply with Version 2.2 must have this method return the integer 2.
Specified by:
getMajorVersion in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Returns:
2

getMinorVersion

public int getMinorVersion()
Description copied from interface: ServletContext
Returns the minor version of the Servlet API that this servlet container supports. All implementations that comply with Version 2.2 must have this method return the integer 2.
Specified by:
getMinorVersion in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Returns:
2

getMimeType

public java.lang.String getMimeType(java.lang.String file)
Description copied from interface: ServletContext
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 are "text/html" and "image/gif".
Specified by:
getMimeType in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
file - a String specifying the name of a file
Returns:
a String specifying the file's MIME type

getResource

public java.net.URL getResource(java.lang.String uriInContext)
                         throws java.net.MalformedURLException
Get a Resource. If no resource is found, resource aliases are tried.
Specified by:
getResource in interface ServletContext
Parameters:
uriInContext -  
Returns:
 
Throws:
java.net.MalformedURLException -  

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String uriInContext)
Description copied from interface: ServletContext
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.

Specified by:
getResourceAsStream in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
name - a String specifying the path to the resource
Returns:
the InputStream returned to the servlet, or null if no resource exists at the specified path

getRequestDispatcher

public RequestDispatcher getRequestDispatcher(java.lang.String uriInContext)
Description copied from interface: ServletContext
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.

Specified by:
getRequestDispatcher in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
path - a String specifying the pathname to the resource
Returns:
a RequestDispatcher object that acts as a wrapper for the resource at the specified path
See Also:
RequestDispatcher, ServletContext.getContext(java.lang.String)

getNamedDispatcher

public RequestDispatcher getNamedDispatcher(java.lang.String name)
Description copied from interface: ServletContext
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.

Specified by:
getNamedDispatcher in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
name - a String specifying the name of a servlet to wrap
Returns:
a RequestDispatcher object that acts as a wrapper for the named servlet
See Also:
RequestDispatcher, ServletContext.getContext(java.lang.String), ServletConfig.getServletName()

getServlet

public Servlet getServlet(java.lang.String name)
Deprecated.  

Specified by:
getServlet in interface ServletContext

getServlets

public java.util.Enumeration getServlets()
Deprecated.  

Specified by:
getServlets in interface ServletContext

getServletNames

public java.util.Enumeration getServletNames()
Deprecated.  

Specified by:
getServletNames in interface ServletContext

log

public void log(java.lang.String msg)
Servlet Log. Log message to servlet log. Use either the system log or a LogSinkset via the context attribute org.mortbay.jetty.servlet.Context.LogSink
Specified by:
log in interface ServletContext
Parameters:
msg -  

log

public void log(java.lang.Exception e,
                java.lang.String msg)
Specified by:
log in interface ServletContext

log

public void log(java.lang.String msg,
                java.lang.Throwable th)
Description copied from interface: ServletContext
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.
Specified by:
log in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
message - a String that describes the error or exception
throwable - the Throwable error or exception

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Description copied from interface: ServletContext
Returns a String containing the real path for a given virtual path. For example, the virtual path "/index.html" has a real path of whatever file on the server's filesystem would be served by a request for "/index.html".

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. This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).

Specified by:
getRealPath in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Parameters:
path - a String specifying a virtual path
Returns:
a String specifying the real path, or null if the translation cannot be performed

getServerInfo

public java.lang.String getServerInfo()
Description copied from interface: ServletContext
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).

Specified by:
getServerInfo in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Returns:
a String containing at least the servlet container name and version number

getInitParameter

public java.lang.String getInitParameter(java.lang.String param)
Get context init parameter. Delegated to HandlerContext. Init Parameters differ from attributes as they can only have string values, servlets cannot set them and they do not have a package scoped name space.
Specified by:
getInitParameter in interface ServletContext
Parameters:
param - param name
Returns:
param value or null

getInitParameterNames

public java.util.Enumeration getInitParameterNames()
Get context init parameter names. Delegated to HandlerContext.
Specified by:
getInitParameterNames in interface ServletContext
Returns:
Enumeration of names

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Get context attribute. Delegated to HandlerContext.
Specified by:
getAttribute in interface ServletContext
Parameters:
name - attribute name.
Returns:
attribute

getAttributeNames

public java.util.Enumeration getAttributeNames()
Get context attribute names. Delegated to HandlerContext.
Specified by:
getAttributeNames in interface ServletContext
Following copied from interface: javax.servlet.ServletContext
Returns:
an Enumeration of attribute names
See Also:
ServletContext.getAttribute(java.lang.String)

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Set context attribute names. Delegated to HandlerContext.
Specified by:
setAttribute in interface ServletContext
Parameters:
name - attribute name.
value - attribute value

removeAttribute

public void removeAttribute(java.lang.String name)
Remove context attribute. Delegated to HandlerContext.
Specified by:
removeAttribute in interface ServletContext
Parameters:
name - attribute name.

getIds

public java.util.Enumeration getIds()
Deprecated. From HttpSessionContext

Specified by:
getIds in interface HttpSessionContext

getSession

public HttpSession getSession(java.lang.String id)
Deprecated. From HttpSessionContext

Specified by:
getSession in interface HttpSessionContext

sessionCount

public int sessionCount()
Returns:
Number of valid sessions

newSession

public HttpSession newSession()

access

public static void access(HttpSession session)

isValid

public static boolean isValid(HttpSession session)

setSessionTimeout

public void setSessionTimeout(int timeoutMinutes)
Set the default session timeout.
Parameters:
default - The timeout in minutes

stop

public void stop()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.