The benefits of struts for program developers

Source: Internet
Author: User

Not very busy recently, so decided to understand about Java EE related content. Now that you have a basic idea of what the servlet and JSP are all about, you are looking at struts. In the process of watching struts, I always have a doubt: why use struts?

Struts is the implementation of the MVC2 model, so many of the books on struts with the servlet to do a meeting with the MVC2 requirements of the Web application, and then use struts to do a similar function of the Web application. But in contrast to the two approaches, I find that struts does not seem to be a great convenience to developers. Here's my comparison:

Views: Same as both

Controller: Using struts does not completely get rid of this layer, the developer still needs to write an action. Using the Servlet method, it is also written as a servlet acting as the controller. There is no difference in the amount of code, the same in the logic of the program;

Model: Both

The main difference between the two: Struts has one more actionservlet.

Since writing a servlet like acition can act as a controller, what is the point of Actionservlet when struts provides the action?

Actionservlet's role is to intercept user requests and forward user requests to the appropriate action, and its Web application is a custom servlet.actionservlet that sends a user request directly to the function equivalent to the action, injecting a Actionform object and a Actionmapping object. After this process, struts brings the following practical benefits for developers: through Actionmapping,action, forwarding is not forwarded to an actual page. Instead, it is forwarded to an object that has already been configured in Strus-config.xml. This means that the forwarded pages can be replaced without changing the action code, and if there is no actionmapping, when there are 100 action to replace the forwarding page, we have to find the 100 action in a huge web application, modify its forwarding page, And then recompile them again. With the actionmapping, just modify the appropriate configuration in the struts-config.xml, so that it is easy to find, without recompiling.

One of the main questions now is: How likely is a Web application to replace a forwarding page once it has been put into use? Action forwarding pages, are generally directly to the user to show the JSP page. In software engineering, all the parts that are directly involved with the user are very easy to change.

Of course there are other conveniences to struts, but it's not enough to impress me with struts, even if it offers a rich tag library.

The final important reason for me is that I really need to adopt a framework like struts. Of course, first I've always believed in the idea that the MVC model advocates: separating views from models. The benefits of being independent of the parts that interact with the user are obvious.

First of all, as mentioned earlier, the part that interacts with the user is the easiest to change, the independence of the view means the isolation of the change, and then the view is separated, and the developer can focus on the process of business processes. A large system, the most complex of the most important part is to deal with business processes. But the reality is that cumbersome interface processing takes up a lot of programmers or even most of the time.

I believe in the benefits of the MVC model, so I will certainly adopt this pattern when developing Web applications, but I don't need struts because the servlet allows me to implement the MVC model. My idea seems natural, but there is a prerequisite: every time I develop a Web application, I must consciously write it in strict accordance with the MVC specification. It doesn't look very difficult, but it's hard to do. Because sometimes it seems natural and simple to embed a few lines of code into the business process, so I really do. After a while, I suddenly found that my business process and interface display parts are mixed again. That's when I really believe I'm going to use Struts.

Because struts can regulate the behavior of programmers. Maybe struts doesn't reduce the actual amount of code, and sometimes the code that doesn't use struts may be simpler, but the Web apps that are written by struts must conform to the MVC model. In my opinion, this is the best advantage of using struts. Standardizing the programmer's behavior and letting the program unknowingly write code that conforms to an excellent architecture should be a common and fundamental goal of all frameworks.

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.