SECTION 2: THE STRUCTURE AND DEPLOYMENT OF MODERN SERVLET WEB APPLICATIONS

Section 2
2.1 Identify the structure of a Web Application and Web Archive file, the name of the WebApp deployment descriptor, and the name of the directories where you place the following:
  • The WebApp deployment descriptor
  • The WebApp class files
  • Any auxiliary JAR files
2.2 Match the name with a description of purpose or functionality, for each of the following deployment descriptor elements:
  • Servlet instance
  • Servlet name
  • Servlet class
  • Initialization parameters
  • URL to named servlet mapping

Section 2 - The Structure and Deployment of Modern Servlet Web Applications

2.1 Identify the structure of a Web Application and Web Archive file, the name of the WebApp deployment descriptor, and the name of the directories where you place the following:

  1. The WebApp deployment descriptor
  2. The WebApp class files
  3. Any auxiliary JAR files
  1. the structure of a Web Application

    The following web application hierarchy is placed under a context root directory within the server's WebApps directory (or something similar, depending on the server) :

    • /[any files to be served to the client, e.g. index.html, images/banner.gif]
    • /WEB-INF/web.xml
    • /WEB-INF/lib/[any required jar files]
    • /WEB-INF/classes/[servlet and support class files in their package hierarchies, e.g. com/mycorp/frontend/CorpServlet.class]
  2. the structure of a Web Archive file
    • this is a JAR archive of the Web Application structure above; it just has a WAR extension so that people and tools know to treat it differently
    • a WAR file can be placed in a server's WebApps directory, and the server will extract it on start up
  3. the name of a WebApp deployment descriptor: web.xml
  4. the name of the directories where you place the following
    1. The WebApp deployment descriptor at /WEB-INF/web.xml
    2. The WebApp class files at /WEB-INF/classes/
    3. Any auxiliary JAR files at /WEB-INF/lib/

2.2 Match the name with a description of purpose or functionality, for each of the following deployment descriptor elements:

  1. Servlet instance
    <servlet> {servlet-name, servlet-class, init-param, etc.} </servlet>
    declares a servlet instance; included within <web-app> </web-app> tags
  2. Servlet name
    <servlet-name></servlet-name>
    registers the servlet under a specific name
  3. Servlet class
    <servlet-class></servlet-class>
    contains the fully qualified class name of the servlet
  4. Initialization parameters
    <init-param> {param-name, param-value} </init-param>
    defines values that can be set at deployment time and read at run-time via ServletConfig.getInitParameter(String name)
  5. URL to named servlet mapping
    <servlet-mapping> 
      <servlet-name> helloServlet</servlet-name> 
      <url-pattern> /hello.html </url-pattern> 
    </servlet-mapping> 
    
    this maps http://server:port/context_root/hello.html to the helloServlet servlet.
    zero or more mappings may be defined per web app
    4 types of mappings, searched in the following order:
    (a) explicit mappings, e.g. /hello.html  
    (b) path prefix mappings e.g. /dbfile/*  
    (c) extension mappings e.g. *.jsp or *.gif  
    (d) the default mapping "/", identifying the default servlet for the web app
    

Return to top