O'Reilly logo

Java Enterprise in a Nutshell, Third Edition by William Crawford, Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Views in Struts

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 HttpServletRequest or 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 ActionForm.

The ActionForm Class

As we discuss the ActionForm class, please refer to Figure 19-2. The key to understanding ActionForms is to notice that they are situated at a number of places in the request/response lifecycle. In particular, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required