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
- <sky:init method="Com.sky.platform.Login.init" >
- <title>${Title}</title>
- <script>
- Sky.onready (function () {
- $ ("Btnlogin"). On ("click", function Login () {
- var dc = form.getdata ("LoginForm");
- Server.sendrequest ("Com.sky.platform.Login.submit", dc,function (response) {
- if (response&&response. status==0) {
- Alert (response. Message);
- }
- });
- });
- });
- </script>
- <body>
- <form id="LoginForm" method="post" style="display:block;height:100%;" >
- <input name="UserName" type="text"/>
- <input name="Password" type="Password"/>
- <input id="Btnlogin" type="button"/>
- </form>
- </body>
- </sky:init>
See how this code solves the chaos of the early model 1.
Java code
- <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
- ${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
- server.sendrequest ( "Com.sky.platform.Login.submit", DC, Function (response) {
- if (response&&response. Status==0) {
- alert (response. Message);
- }
- });
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?