Views present information from the model. The typical view architecture used with Struts is JSP, but in fact, any servlet—that is, any path mapped by the container to which Struts can forward control—can serve as a view. We will stick to JSP because it is so common, but increasingly developers are becoming interested in view frameworks with simpler syntax or other niceties, such as Velocity. Thankfully, Struts can still be used if you decide to pursue these alternatives.
The interesting question regarding views is how they communicate with
Actions and the request processor. Views
need to transfer data in two ways. First, they must be able to pick up
data that is provided to them by
Actions. This part is easy: an
Action puts objects into request or session
scope, just as any servlet would; references to these objects may then
be retrieved by the JSP from request or session scope directly through
Java scriplets referencing the
HttpSession objects or through tags, such as
those provided by JSTL (JSP Standard Tag Library) or the Struts Tag
Libraries (more on this topic later in this chapter).
The second requirement for data transfer in the view is to
obtain values that should be displayed in a form. Enter the
As we discuss the
ActionForm class, please refer to Figure 19-2. The key to
ActionForms is to notice that they are situated at a number of places in the request/response lifecycle. In particular, ...