What benefits does Struts bring to you during program development?

Source: Internet
Author: User

Struts is the implementation of the MVC2 model. Therefore, many struts books use servlet to make a web application that meets the MVC2 requirements, and then struts is used to make a web application with the same function. However, in the comparison between the two methods, I found that struts does not seem to bring great convenience to developers. The following is my comparison:

View: the two are the same

Controller: struts cannot be used to completely get rid of this layer. Developers still need to write action. Using servlet is also used to write a servlet like action to act as the controller. There is no difference between the two in terms of code volume and the same in program logic;

Model: The two are the same

Major difference between the two: struts has an actionservlet

Since a servlet similar to acition can act as a controller, what is the significance of actionservlet after Struts provides action?

Actionservlet is used to intercept user requests and forward user requests to appropriate actions. Its web application directly sends user requests to a custom servlet equivalent to action. actionservlet injects an actionform object and an actionmapping object during interception. After this process, Struts brings the following benefits to developers: Through actionmapping, action is not forwarded to an actual page. Instead, it is forwarded to the objects that have been configured in the strus-config.xml. This means that the forwarded page can be changed without changing the Action Code. If there is no actionmapping, when there are 100 actions, we have to find these 100 actions in a huge web application, modify the forwarding page, and re-compile them. With actionmapping, you only need to modify the corresponding configuration in the struts-config.xml, so that it is convenient to find and do not need to re-compile.

One of the main problems is: what is the possibility of changing the forwarding page after a web application is put into use? Pages forwarded by action are generally JSP pages directly displayed to users. In software engineering, everything that directly deals with users is easily changed.

Of course, Struts certainly has other conveniences, but these are not enough to impress me to use struts, even if it also provides a rich tag library.

In the end, an important reason makes me think that I really need to adopt a framework like struts. Of course, I have always believed in the concept of the MVC model: separating views from models. The advantage of separating the parts of interaction with users is obvious.

First, as described above, the interaction with users is the most vulnerable to changes, and the independence of views means the isolation of changes. Then, after the views are separated, developers can focus on processing business processes. The most complex and core part of a large system is processing business processes. However, the actual situation is that tedious interface processing takes a lot of time for programmers or even a majority of the time.

I believe in the benefits of the MVC model, so I will certainly adopt this mode when developing Web applications, but I don't need struts, because servlet can let me implement the MVC model. My idea seems natural, but there is an implicit premise: Every time I develop a web application, I must consciously write in strict accordance with the MVC specification. This does not seem very difficult, but it is very difficult to do. Sometimes it seems very natural and simple to embed several lines of code about the interface in the business processing process, so I did it. After a while, I suddenly found that my business processing process and interface display were mixed. So far, I really believe that I want to use struts.

Because struts can regulate the behavior of programmers. Maybe struts cannot reduce the actual amount of code, or even sometimes the code without struts may be more concise, but the Web applications written according to struts must comply with the MVC model. In my opinion, this is the biggest benefit of using struts. Standardize the behaviors of programmers and allow the program to write code that conforms to the excellent architecture without knowing it. This should be the common purpose of all frameworks and the fundamental purpose.

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.