File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Can we have more than one controller in MVC pattern? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Can we have more than one controller in MVC pattern?" Watch "Can we have more than one controller in MVC pattern?" New topic
Author

Can we have more than one controller in MVC pattern?

Naina Si
Ranch Hand

Joined: Nov 05, 2003
Posts: 134
Can we have more than one controller in MVC pattern
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Sure! Depends on the needs of your system.

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Struts is an good example, you can have more than 1 ActionDispatcher.

Nick
Bryan Basham
author
Ranch Hand

Joined: Apr 30, 2001
Posts: 199
It depends on what you mean by "controller".

There are basically two types of controllers: application and infrastructure. An application controller is any code that responds to a specific user request. Such controllers are used to implement the activity flow within use cases in your application. An infrastructure controller is any code that responds generically to user requests and perform functionality that spans multiple application user requests.

For example, in Struts the Action classes you create are application controllers. These are things like "add an item to my shopping cart," "search for a product in the catalog," "display my shopping cart," "log in," "log out," and so on.

The ActionServlet class is the infrastructure controller. That servlet performs generic operations, such as populating form beans, validating form beans, executing the app. controller (an Action object), and dispatching to the appropriate view based on the execute methods return value. [Well, technically the RequestProcessor class/subclass does this work, but the ActionServlet delegates that work to the RequestProcessor.]

So in Struts, any given user request is likely to through the infrastructure controller (ActionServlet) first, which then dispatches the request to the appropriate application controller which performs the actual functionality for that request.

HTH,
Bryan
[ October 20, 2004: Message edited by: Bryan Basham ]
Naina Si
Ranch Hand

Joined: Nov 05, 2003
Posts: 134
Thanks much for the clear cut explanation.

When i say controller, i meant the servlet controlling the flow to different models.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Thus, could (or should) we have a design that:

There is 1 single entrance point (FrontController) to the system (say Servlet X for login checking), while it will then dispatch the requests to corresponding Servlets, which acts as MVC?

Nick
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we have more than one controller in MVC pattern?