问题
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