Today's thinking: what is the significance of the existence of struts in the MVC series framework?

Source: Internet
Author: User

Struts is actually synonymous with MVC, so the mention of MVC has to mention early Modelⅰ. At that time, the JSP page mixed with a large number of Java Scriptlet script statements, for the sake of maintainability, someone proposed the Modelⅱ, which is now the MVC pattern. So it can be seen that the proposed MVC is based on the early JSP page mixed with a large number of Java script scripts under the premise. In this case, the advent of MVC has made the world of JSPs much cleaner.

Although the MVC framework, it has been pointed out that the framework of the struts system can only be considered a pseudo-mvc. Why do you say that? Because it doesn't have the most central part of MVC: Event control, struts looks more like a control-forwarding framework. So is this jump necessary?

Since the beginning of the 2005, Ajax has begun to emerge, so far, not to mention Ajax has reached the point of mature applications, but looking back to MVC, can there be another more elegant, clear ideas to replace the early Modelⅰ?

Let's look at a small piece of code:

Java code
  1. <sky:init method="Com.sky.platform.Login.init" >
  2. <title>${Title}</title>
  3. <script>
  4. Sky.onready (function () {
  5. $ ("Btnlogin"). On ("click", function Login () {
  6. var dc = form.getdata ("LoginForm");
  7. Server.sendrequest ("Com.sky.platform.Login.submit", dc,function (response) {
  8. if (response&&response. status==0) {
  9. Alert (response. Message);
  10. }
  11. });
  12. });
  13. });
  14. </script>
  15. <body>
  16. <form id="LoginForm" method="post" style="display:block;height:100%;" >
  17. <input name="UserName" type="text"/>
  18. <input name="Password" type="Password"/>
  19. <input id="Btnlogin" type="button"/>
  20. </form>
  21. </body>
  22. </sky:init>



See how this code solves the chaos of the early model 1.

Java code  
    1. <sky:init method="Com.sky.platform.Login.init" >


The Com.sky.platform.Login class can be thought of as the background binding class for this page, and its ideas come from Aspx.net
Init method used to do the initialization of the page action
The data in the page like this need to be obtained can be implemented as follows:

Java code  
    1. ${title}



A very important part of struts ' control and forwarding is the ability to get the data to be placed in the page attribute range, and now in this way can realize the Strtus data acquisition function.

Someone would ask, like a list or something, how can you make a ${}? The answer is: we can implement the corresponding AJAX-style list control in the foreground, and so on ...

Like forms other we can also use Ajax to directly submit the method of the background binding class to implement the way

Java code   
    1. server.sendrequest ( "Com.sky.platform.Login.submit", DC, Function (response) {  
    2.              if (response&&response. Status==0) {  
    3.                  alert (response. Message);   
    4.             }   
    5.         });   


The difference between this programming idea and the nature of the Struts MVC framework is that it completely discards the control-forwarding configuration it needs, because struts is used to configure the files that control the forwarding itself only to implement its MVC function. So now that we have an alternative solution to the early Model1 chaos, is there any need for the control and forwarding of the Struts MVC framework?

In fact, a similar solution to this idea is JSF, but JSF does not use the concept of a background binding class as Aspx.net does, and it does not abandon the routing navigation configuration of class struts.

This is only a personal point of view, Welcome to discuss, treatise, put forward their own views!  

Today's thinking: what is the significance of the existence of struts in the MVC series framework?

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.