Struts and MVC layered understanding

Source: Internet
Author: User

From: http://hi.baidu.com/wang668/blog/item/ce3fc3889fc29a92a5c27219.html

I attended an interview today and asked the above questions during the interview. At that time, I was puzzled and I was blinded by layer V. After I came back, I found the following information on the Internet:

Problem: Could you give me a standard answer to two small questions in the MVC2 design mode of struts? Thank you!

I have learned the MVC2 design mode of struts these days. I have different answers to some questions and tutorials! Confused me! Could you give me a standard answer to two small questions in the MVC2 design mode of struts? Thank you!

1. the actionform class and action class implement the business logic functions in the end, whether they belong to the C-layer (controller, that is, the Controller layer) or to the M-layer (model, that is, the model layer) or the V layer (view layer )? (Sun weiqin's book seems to have added the actionform class to the V layer! Confuse people !)
2. If the class action should be written to the C-layer in the following tutorial, isn't m-layer in struts? What is m layer? (I read the first small example of struts entry register in the struts in action Chinese version. If the registeraction class is assigned to the C layerProgramIs there no m layer ?)

Answer 1:

1. I think the actionform should belong to the V layer. Its function is to temporarily store the HTTP request data, and it does not involve any business logic.
2. I am now learning to develop a project with Struts, read a document of struts, I think the main controller in struts is actionservlet configuration in the struts-config.xml, used to control the global, and action as the name suggests, action, it should be from the Controller. First, the V layer generates an HTTP request, which is first received by the actionservlet, then the corresponding URL is searched in the XML file, and then the corresponding action class processes the specific data.
3. In some entry examples of struts, the corresponding m layer is not necessarily required. The role of the m layer is to encapsulate data.

 

Answer 2:Actionform is a V layer that transfers data with JSP to verify data. Action is C, controller, it is only responsible for calling the business object, calling the M-layer method, and then forwarding.
The m layer is a method for data operations. It usually involves some entity beans and business logic operations. Of course, in the m layer, the lineline can be further layered.

 

Answer 3:Actionform belongs to the V layer. It temporarily stores JSP form data and verifies the field before reaching the action.
Action belongs to the C control layer. It is only responsible for calling the M-layer method and forwarding it to the corresponding page or action.
In fact, Struts itself does not provide a real m layer.

 

Answer 4: actionform is a view layer that only transmits data in the middle. Strictly speaking, action cannot be completely classified into the control layer, because the control logic can be directly written in the action, it plays a role of scheduling and shunting for actionservlet.
In fact, according to Sun weiqin's point of view, action is between C and V, I very much agree with this point of view. struts does not implement the model specification. As an MVC framework, I don't think this is necessary, because as a developer, he will face the most model layer, it can be used freely. It can be called by action. It does not matter whether it is used by EJB or hibernate.
You Can See struts. actionservlet only intercepts the request of the expected customer, parses the request, reads the configuration file, and calls the corresponding action of the configuration according to the form, you can see Source Code .

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.