Expert Spring MVC and Web Flow

(Dana P.) #1

URI Mapping to Controllers


This is a good time to review how a full URI is mapped to a Controller. There are three compo-
nents to a mapped URI path, the WebApplicationContextpath, the servlet mapping, and the
Controllermapping.
If you recall, we defined the HomeControllerwith /homeas its URL, which gets appended to
the mapping of the servlet, which has just been mapped to /app/*. The third piece of the puzzle
is the WebApplicationContextpath. In this case, if the context path is JumpIntoSpringMVC, the
full URL to the HomeControllerwould be http://www.example.com/JumpIntoSpringMVC/app/home.


Full web.xml


Putting it all together, we now present the full web.xml, shown in Listing 4-14.


Listing 4-14.Full web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


<display-name>JumpIntoSpringMVC</display-name>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>


CHAPTER 4 ■JUMP INTO SPRING MVC 61
Free download pdf