7
votes

If you look at the Java EE FrontController sequence diagram, the Controller delegates the request to Dispatcher and the document says that:

A dispatcher is responsible for view management and navigation, managing the choice of the next view to present to the user, and providing the mechanism for vectoring control to this resource.

In Spring MVC, the DispatcherServlet acts as FrontController (as mentioned in Book by Craig Walls), and this Servlet delegates the request to other controllers that in turn calls appropriate Service class (for processing the request) and then returns an instance of ModelAndView to DispatcherServlet again.

So roughly this is how request usually travels:

Client -> DispatcherServlet -> Controller -> Service -> DAO

If you compare this flow with Java EE FrontController pattern sequence diagram, it appears that DispatcherServlet is not true FrontController.

What do you say about this?

1

1 Answers

12
votes

I would say that the DispatcherServlet fills the rolls of the front-controller and dispatcher. However, rather than delegating directly to the view the DispatcherServlet delegates to another controller. This enables you to better separate your presentation from your business logic. In the "pure" front-controller paradigm, you might have to add some business logic to your views.

In short, the DispatcherServlet accomplishes the same goals as the Front Controller pattern. But it does deviate from it slightly by allowing you to add another layer of controllers to the dispatcher. I think this is a good thing.