Chapter 3. The Web Container Model

For the ServletContext initialization parameters: write servlet code to access initialization parameters; and create the deployment descriptor elements for declaring initialization parameters.

The following methods of the ServletContext interface allow the servlet access to context initialization parameters associated with a Web application as specified by the Application Developer in the deployment descriptor:

  • 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.

  • 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.

Initialization parameters are used by an Application Developer to convey setup information. Typical examples are a Webmaster’s e-mail address, or the name of a system that holds critical data.

public interface ServletContext {

	public java.lang.String getInitParameter(java.lang.String name);
	public java.util.Enumeration getInitParameterNames();

Context initialization parameters that define shared String constants used within your application, which can be customized by the system administrator who is installing your application. The values actually assigned to these parameters can be retrieved in a servlet or JSP page by calling:

javax.servlet.ServletContext context = getServletContext(); 
String value = context.getInitParameter("webmaster");
where "webmaster" matches the param-name element of one of these initialization parameters.

You can define any number of context initialization parameters, including zero:

			The EMAIL address of the administrator to whom questions
			and comments about this application should be addressed.


The context-param element contains the declaration of a web
application’s servlet context initialization parameters.

<!ELEMENT context-param (param-name, param-value, description?)>


Professional hosting     Belorussian informational portal         Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     Free SCJP 5.0 (Tiger) Study Guide     Free Mock Exam Engine     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide