In Struts2, a Controller dispatches a request to the Action and then passes it to the back-end logic, which could be regarded as a very big model, to process the request, and JSP represents Views.
How to define the Action in Struts 2? Definitely it's not a View. Is it the Controller or Model?
Struts actions are controllers in the sense of the MVC pattern. I think the discussion of the value stack and ActionContext
, as well as getter methods in action classes confuses the issue. In general, these are simply containers for other objects (usually Model objects).
While @AndreaLigios points out that you can retrieve objects from the action using various get methods, that's more an issue of diluting the actions cohesion by giving it additional responsibilities normally assigned to model object. Yes, it's important to evaluate the responsibilities of your objects when you're considering what the do (or should be doing).
Put most simply, the responsibilities of the major components in all MVC framework are as follows:
When you look at a specific MVC framework like Struts (or Spring MVC) you'll see that the frameworks usually provide both Controller and View components, but it's your job to build out the Model yourself. Even so, Struts provides a wealth of additional objects and components, like ActionContext
, that make it easier to access your Model objects from your View components.