Application Servlet

Every Tapestry application has a single servlet, which acts as a bridge between the servlet container and the application engine. The application servlet is an instance of ApplicationServlet.

The first thing a servlet does, upon initialization, is read the application specification. To do this, it must know where the application specification is stored.

Specifications are stored on the classpath, which means in a JAR file, or in the WEB-INF/classes directory of the WAR.

The servlet determines the location of the application specification from the web deployment descriptor. A servlet initialization property, org.apache.tapestry.application-specification provides the locations of the specificiation as a path.

Example 5.1. Web Deployment Descriptor


<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
 "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
  <display-name>Tapestry Virtual Library Demo</display-name>
  <servlet>
    <servlet-name>vlib</servlet-name>
    <servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
    <init-param>
    	<param-name>org.apache.tapestry.application-specification</param-name>
    	<param-value>/net/sf/tapestry/vlib/Vlib.application</param-value>
    </init-param>
  	<load-on-startup>0</load-on-startup>
  </servlet>
  
  <!-- The single mapping used for the Virtual Library application -->

  <servlet-mapping>
    <servlet-name>vlib</servlet-name>
    <url-pattern>/app</url-pattern>
  </servlet-mapping>
  
  <session-config>
  	<session-timeout>15</session-timeout>
  </session-config>
    
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

The servlet's main job is to find or create the IEngine instance. It then delegates all the behavior for processing the request to the application engine. Encoded in the URL will be a particular application service; the engine delegates to the service to perform the real work of handling the request.

Figure 5.1. ApplicationServlet Sequence

ApplicationServlet Sequence