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:
- The WebApp deployment descriptor
- The WebApp class files
- Any auxiliary JAR files
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]
- 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
- the name of a WebApp deployment descriptor: web.xml
- the name of the directories where you place the following
- The WebApp deployment descriptor at /WEB-INF/web.xml
- The WebApp class files at /WEB-INF/classes/
- 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:
- Servlet instance
<servlet> {servlet-name, servlet-class, init-param, etc.} </servlet>
declares a servlet instance; included within <web-app> </web-app> tags
- Servlet name
<servlet-name></servlet-name>
registers the servlet under a specific name
- Servlet class
<servlet-class></servlet-class>
contains the fully qualified class name of the servlet
- 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)
- 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