How does Front Controller fit in?

Oh yeah. Front Controller is another J2EE pattern, and it just happens to be on the exam. Actually, Struts is a really fancy example of using a Front Controller pattern. The basic idea of the Front Controller pattern is that a single component, usually a servlet but possibly a JSP, acts as the single control point for the presentation tier of a web application. With the Front Controller pattern, all of the app’s requests go through a single controller, which handles dispatching the request to the appropriate places.

In the real world, it’s rare to implement a Front Controller all by itself. Even a really simple implementation usually includes another J2EE pattern called an Application Controller. Struts includes a class called the RequestProcessor, which is ultimately responsible for the handling of HTTP requests.

Although the exam might contain questions about the Front Controller pattern, you’ll be fine if you remember the benefits of Struts, and the fact that Struts is simply a Front Controller with all the bells and whistles.

Eight features that Struts adds to a Front Controller

1 Declarative Control: Struts allows you to create declarative maps between request URLs, validation objects, model-invoking objects, and views.

2 Automated Request Dispatching: The Action.execute() method returns a symbolic ActionForward which tells the ActionServlet which view to dispatch to. This provides another layer of abstraction (and loose coupling) between the controller and view components.

3 DataSources: Struts can provide DataSource management.

4 Custom Tags: Struts provides dozens of custom tags.

5 Internationalization Support: Error classes and custom tags have internationalization support.

6 Declarative Validation: Struts provides a validation framework that removes the need to code the validate method in your form beans. The rules for validating a form are configured in an XML file and can be changed without affecting your form bean code.

7 Global exception handling: Struts provides a declarative error handling mechanism similar to <error-page> in the DD. However, with Struts the exceptions can be specific to the application code in your Action object.

8 Plug-ins: Struts provides a PlugIn interface with two methods: init() and destroy(). You can create your own plug-ins to enhance your Struts application, and they will be managed for you. For example, the Validator framework is initialized using a plug-in.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset