Recent top five:
Let's talk about exceptions ...
How do you handle exceptions? Do you think upfront about the type of exceptions that you want to catch or do you just let
the outside world handle it?
-- Jeroen van Bergen in JW Blogs
| Enterprise AJAX - Transcend the Hype |
| Memory Analysis in Eclipse |
| Oracle Compatibility Developer's Guide |
| Memory Analysis in Eclipse |
The objective here is to have JSP code that resembles HTML to the greatest possible degree, by moving all processing code into JavaBeans. The benefit of that approach is that the HTML programmers and graphic designers can do the presentation development (using one of many HTML editors) while you, the Java programmer, can do the programming logic. In addition, the approach makes it easy for you to provide different look and feels for the same Web application.
The framework I'll present here uses the Template Method pattern to enforce common design across the entire application and implement common behavior in each JSP. The common behavior includes, but is not limited to, page state management, common page processing, common error processing, and a mechanism for sharing information between pages. Those are all defined only once, leaving you to deal only with the page-specific details.
I'll present a simple "voting" application as an example of how you can use the framework. You should have basic JSP and Java knowledge, and some UML knowledge is desirable but not mandatory.
This section gives an overview of the framework core participants, as well the example voting application. Figure 1 shows a UML diagram of the framework's structure:
Figure 1. UML Class Diagram
Click on thumbnail
to view full-size image.
The framework's central piece consists of two common JSP include files and two classes, described below. Their role is to carry out the common behavior.
includeheader.jsp: Include JSP file that must be statically included in the beginning of each JSP.
includefooter.jsp: Include JSP file that must be statically included at the end of each JSP.
AbstractJSPBean: Abstract class that you should use as a super type for all JSP JavaBean classes. This is the framework's core class.
SharedSessionBean: Used to provide associations between all JSP JavaBean objects within one HTTP session.
The purpose of a JSP Webpage is solely presentation. Each JSP must have a corresponding JavaBean that performs the page-specific
logic. Each JSP page must statically include includeheader.jsp and includefooter.jsp. Each JavaBean must extend the AbstractJSPBean, which contains the template methods that carry out the common behavior.
The voting application consists of the following JSPs and their corresponding JavaBeans:
login.jsp, LoginJSPBean: Authenticates and logs in the voter
vote.jsp, VoteJSPBean: Performs the voting
confirmation.jsp, ConfirmationJSPBean: Displays confirmation and voting results
I will not examine the classes that emulate database and business logic (Voter, Candidate, and VoteDB) in great detail, but they are required for the example to function properly.