13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

438Chapter 19JSP: Servlets Turned Inside Outservlet). The forEach will iterate over those values without you having to codethe explicit next() calls or index your way through an array.The bottom of the loop is delimited by the closing tag:For more informati<strong>on</strong> <strong>on</strong> these and other tags, check out• http://java.sun.com/products/jsp/jstl• http://jakarta.apache.org/products/jsp/jstl• The references at the end of this chapterBey<strong>on</strong>d the standard library of tags, there are other third-party collecti<strong>on</strong>sof tags; you can also create your own libraries, called custom tag libraries. Whilea useful and powerful thing to do if you have a large JSP-based applicati<strong>on</strong>,such details would expand this book well bey<strong>on</strong>d its scope. If you’re interestedin this topic, please follow up with some of the excellent references at the endof this chapter.19.4USING JSP WITH BUDGETPROWe could have taken the BudgetPro example from the previous chapter andsimply translated it all into JSP files. The reas<strong>on</strong> we didn’t is that it’s not howyou are likely to find JSP used “in the wild.” Since JSP files become servlets, itis not uncomm<strong>on</strong> to find JSP and servlets mixed together—not arbitrarily, butin a sensible way. Remember the Model/View/C<strong>on</strong>troller (MVC) pattern fromyour readings <strong>on</strong> object-oriented programming and design patterns? 2 Well, JSPmakes for a reas<strong>on</strong>able View, and a plain servlet can act as the C<strong>on</strong>troller. TheModel is typically the database behind all this. That’s what we’ve d<strong>on</strong>e withthe BudgetPro example.We’ve taken the two main chunks of output code—that for the main accountdisplay and the form used for creating subaccounts—and turned those2. If not, then a) you should do some more reading, and b) the MVC pattern is a “classic” wayto divide the work of a GUI into three distinct parts: Model—the data behind what you aredoing or displaying; View—a particular way to display that data; and C<strong>on</strong>troller—an objectthat acts as the “traffic cop” to various inputs and events, sending messages to either the View,or Model, or both.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!