Expert Spring MVC and Web Flow

(Dana P.) #1
■NoteThe URI-to-Controllermapping strategy is fully pluggable, making it easy to change if the default
is not sufficient.

Listing 4-9.spring-servlet.xml

<?xml version="1.0"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<bean name="/home"
class="com.apress.expertspringmvc.flight.web.HomeController">
<property name="flightService" ref="flightService" />
</bean>

</beans>

As you can see, we have also configured the FlightServiceproperty of the HomeController,
thus resolving its dependencies.
The spring-servlet.xmlfile will be stored in the /WEB-INFdirectory for now (which is the
default location), but the location is completely configurable.

View
With the Controllerbuilt and configured, it’s time now to build and configure the View. To
review, in the handleRequestInternal()(from Listing 4-8) method we retrieved a list of special
deals and placed them in the model. We will now render the list of special deals into XHTML.
For our examples, and to keep things simple, we will use JSP to render the views, includ-
ing the home page. Listing 4-10 contains the full JSP for the home page.

Listing 4-10.home.jsp

<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Flight Booking Service</title>
</head>
<body>
<h1>Welcome to the Flight Booking Service</h1>
<p>We have the following specials now:</p>

56 CHAPTER 4 ■JUMP INTO SPRING MVC

Free download pdf