Which files are responsible specifically for Model, View and Controller in struts2 MVC framework? [duplicate]

南笙酒味 提交于 2019-12-11 05:10:02

问题


My MVC concept is not clear.

It seems me that .xml files are for Modeling; .jsp files are for Viewing; .java files are for Controlling. This is actually represents MVC system.

I have the working basic concepts on MVC formula but I am not clear on which files are responsible specifically?


回答1:


First of all, dive into Wikipedia.

Your conception of MVC is wrong, and so is dividing concepts using technologies (.xml, .jsp, .java...);

  • The Model contains the data (WHAT is displayed);
  • The View renders the data to the user (HOW it is displayed);
  • The Controller manipulates the data, both automatically or based on user's interaction (WHY it is displayed).

Then, when you've clear what MVC is, try to understand how Struts2 implements MVC:

  • the JSP file is the View;
  • the Action is the Controller (and part of the Model);
  • the Model is whatever you use to carry the data (Bean, POJO, Map, String, etc...), unless you explicitly define a model object through ModelDriven (but don't), in which case that object is the Model.

EDIT: as suggested by Dave, it is worth mentioning that, when talking of Actions, we're also implying the StrutsPrepareAndExecuteFilter (responsible of which Action to call) and the Interceptor Stack (through which every Action must pass before - and after - a result execution).



来源:https://stackoverflow.com/questions/43336883/which-files-are-responsible-specifically-for-model-view-and-controller-in-strut

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!