Java Reference
In-Depth Information
Listing 3-3.
web.xml
<web-app>
<servlet>
<servlet-name>insurance</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>insurance</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
The interesting part in Listing 3-3 is the URL mapping. It shows that this servlet has
been configured to handle all requests ending with
.do
in the URL. If you are an experi-
enced Java EE developer and have worked with the Apache Struts framework, you will
immediately see its similarity to the
ActionServlet
.
On initialization, the
DispatcherServlet
looks for a configuration file with the naming
convention
<servlet-name>-servlet.xml
in the
WEB-INF
folder of the web application. This
XML file contains the configuration information about all the beans, including the page
controllers and view managers that will be managed by the Spring IOC container. The
front controller loads this file to start the Spring web application context and get access
to the Spring IOC container. In our case, this file will be named
insurance-servlet.xml
.
This is shown in Listing 3-4 with only the page controllers.
Listing 3-4.
insurance-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="
http://www.springframework.org/schema/beans"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
<bean name="/createPolicy.do"
class="com.apress.insuranceapp.web.CreatePolicyController"/>
<bean name="/updatePolicy.do"
class=" com.apress.insuranceapp.web.UpdatePolicyController"/>
</beans>
