If the two checks mentioned earlier are not required, then the UrlFilenameView å
Controller class can be combined with view resolvers to implement page controllers that
pass only the logical view name. I will cover this kind of controller in greater detail while
discussing the Dispatcher View pattern later in this chapter.
Most of the use cases in a web application operate by collecting the information supplied
in HTML forms and then performing business actions based on this form data. It is pos-
sible to get all the form data from the HttpServletRequest object primarily using the
getParameter method. It is a bad practice to pass the request object to the business tier
because it would then be tied down to clients of a specific protocol type. Hence, the
getParameter method can be used to retrieve all required data to populate a JavaBean
object. This JavaBean object is passed to the business layer.
Putting the JavaBean creation logic in the controller violates SRP. Any change to the
form field may cause a change in the controller. A flexible and clean design would be to
create this JavaBean object outside the controller and pass it as a parameter to the con-
troller. This requirement is fulfilled by controllers that implement the AbstractCommand å
Controller class. The handler adapter populates the POJO object from the
HttpServletRequest object, which is then passed to the controller. It maps the form field
names to the properties of the POJO.
The JSP shown in Listing 3-20 is used to underwrite new policies. It presents a simpli-
fied policy underwriting form with only three fields. Listing 3-21 shows the JavaBean
class, which is used to populate the form data. Some developers call these classes com-
mand classes . This name is inappropriate, however, because the page controllers are
command objects that implement the command design pattern (GOF). These data
holder classes on the server that populate and store values passed through HTML form
submission are better called form beans .
Listing 3-20. WEB-INF/jsp/createPolicy.jsp
document.policy.action = url;