Confusion in Struts MVC architecture

前端 未结 2 1174
滥情空心
滥情空心 2020-12-22 00:59

I am studying the Struts2 in Action and come to know that Controller in Struts2 is FilterDispatcher and Model is Action. But previously I knew that Action and <

相关标签:
2条回答
  • 2020-12-22 01:21

    I would say that FilterDispatcher is a FrontController and Action is both Model and Controller in one class.

    0 讨论(0)
  • 2020-12-22 01:31

    Actually Struts2 actions are controller delegates. And Struts2 provides a value stack on the view layer which has better support, and if you want to use a pseudo-model then action should implement ModelDriven interface. You should also note that Struts2 actions are simple POJOs managed by Struts2 container. This is a bit different in the MVC point of view, also known as MVC Model2. For example, the description of the model given by wikipedia:

    The central component of MVC, the model, captures the behavior of the application in terms of its problem domain, independent of the user interface.[5] The model directly manages the data, logic and rules of the application.

    Looks like a model is defined externally and probably managed by persistence layer. Struts2 controller works with the model via its delegates.

    A view can be any output representation of information, such as a chart or a diagram; multiple views of the same information are possible, such as a bar chart for management and a tabular view for accountants.

    In Struts2 the view is a result returned by the controller in response object. Struts2 can use different result types and templates to produce a response.

    The controller, accepts input and converts it to commands for the model or view[6].

    Struts2 uses a request for the input, which is handled by the controller to find appropriate delegate, which can work with the business model directly or on the service layer.

    To answer your question having in mind that is said here, your last statement is closer to truth. Struts2 can help you with the controller and presenting a view, but it can't help you to design a model. However, there are many other frameworks that do it, for example Hibernate, which you can use with Struts2 to complete absent MVC component in your application.

    0 讨论(0)
提交回复
热议问题