The function of a controller object is to serve as a mediator between the view and the model. A Struts Action class does exactly that. It gets information from the view, sends it on to model object, and returns results to the view.
In my mind, a Struts action belongs firmly in the controller space. [ January 12, 2006: Message edited by: Merrill Higginson ]
Action class forwards request to ActionServlet(controller) and ActionServlet decides where to forward based on struts-config mapping.
ActionServlet receives and processes all requests that change the state of a user's interaction with the application. The servlet delegates the handling of a request to a RequestProcessor object. ActionServlet represents the "controller" component of an MVC architecture.
The RequestProcessor selects and invokes an Action class or delegates the response to another resource.
The Action classes can manipulate the state of the application's interaction with the user, typically by creating or modifying JavaBeans.
Instead of producing the next page of the user interface directly, Action classes generally return an ActionForward to indicate which resource should handle the response. If the Action does not return null, the RequestProcessor forwards or redirects to the specified resource (by utilizing RequestDispatcher.forward or Response.sendRedirect) so as to produce the next page of the user interface.
Action classes are not controller.
Originally posted by Merrill Higginson: The function of a controller object is to serve as a mediator between the view and the model. A Struts Action class does exactly that. It gets information from the view, sends it on to model object, and returns results to the view.
In my mind, a Struts action belongs firmly in the controller space.
[ January 12, 2006: Message edited by: Merrill Higginson ]
While I agree with Vicky that the Struts ActionServlet is the main controller component, I continue to assert that the Action class is also part of the controller space. While it is the ActionServlet and RequestProcessor that actually communicate with the model, the Action class tells them both what to do ... which page to display next, and what data will go on that page.
To me, the real test of which space a component belongs in is "what does it need to know about?". View objects should know only about other view objects and controller objects, as they should never communicate directly to the model. Model objects only need to know about other model objects. They should be "pluggable" to use any view or controller. Conroller objects, on the other hand, need to know about both view objects and model objects in order to mediate between them.
What does the Action class need to know about?
It needs to know about the view. Although it doesn't need to know the name of a JSP, it does need to the name of an ActionForward that will eventually resolve to a JSP. It needs to know that we're using HTTP as the view protocol, because it receives it's input from an HTTPServletRequest and sends its output to an HTTPServletRespone. It needs to know about the javaBeans that are part of the view space in order to pass data to the view.
It needs to know about the model. It has to know which model objects to call in order to get the needed information. It has to know what format that information will be in and may have to modify it to accomodate the view.
Given this test, the Action class is clearly a controller object -- certainly not the only controller object, nor even the main one, but a controller object nonetheless.
The authors of the Struts documentation appear to agree with me on this. They list Action Mappings and Action classes as conroller components. Here's the link:
Merrill is quite correct. The Action class is part of the Controller, and not in any way part of the model. If there were any question as to how the authors of Struts grouped the various components, the Struts User Guide states it quite plainly. Aside from explicitly listing Action as a controller component, it states the following:
The goal of an Action class is to process a request, via its execute method, and return an ActionForward object that identifies where control should be forwarded (e.g. a JSP, Tile definition, Velocity template, or another Action) to provide the appropriate response.
That's a pretty good description of what a controller component does. [ January 14, 2006: Message edited by: Jason Menard ]