1.1.12

Front Controller

Core J2EE Patterns - Front Controller
Design Patterns: Front Controller
Core J2EE Patterns
Front Controller pattern - Wikipedia, the free encyclopedia
P of EAA: Front Controller
Front Controller
Front Controller [Web Application Component Toolkit]

Front Controller pattern - Wikipedia, the free encyclopedia

  • The Front Controller Pattern is a software design pattern listed in several pattern catalogs.
  • The pattern related to the design of web application.
  • It "provides a centralized entry point for handling requests."
My understanding

The most straightforward to implement a web application feature:
  • Create a start point page, or use a result of another request.
  • Have the client to fill in some data if necessary.
  • Have the client to submit the data to send out a request.
  • Process the request and response with some new information/page.
To fulfill this logic, you just need a form and point out to a response JSP page which is subject to process the request and response with with information.

Centralized dispatcher mechanism:
  • As a software system, web applications have a log of reusable items, including:
    • Authentication management.
    • Consistent page styles.
    • Shared business logic/component.
    • Auditing.
    • etc.
To apply for re-usability, you need to make all the request/response processes working in a similar way and make some places for the reusable components to fit in.

Luckily, we have Spring DispatcherServlet or other framework to help us with this requirements. There are no reasons that we should not stick to it.

Basically, this is a first step to develop a good web application.

What's in the book:


  • Use Spring Dispatcher Servlet as the standard access point of most of the web request, instead of having a JSP to handle form requests.
  • Use servlet mapping to map URL patterns to Dispatcher Servlet:
    • Decouple Spring framework.
    • Make the system extensible (You can add as many urls as you want into the system)
  • Use Spring bean container to define the mapping between URL path with a Controller implementation.
    • A controller is a pure Java class with the knowledge to handling internal process of the requests and the view for the responses.
    • This controller handle the business logic in a single purpose class.

Design theories:
  • Decouple the underlying support system. Here is Web server.
    • Comparing to CGI, or bad JSP implementation
  • Make the implementation extensible
    • URL pattern mapping to automatically map things into the dispatcher.
    • You just need to add a new URL with a certain patterns into your system, without changing the dispatcher's configuration. (Many extensible framework haves this theory, such as OSGi.

No comments: