Struts - based on J2EE-based MVC mode implementation
I. Struts's origin of the Web system itself is quite tricky and difficult to handle. For example, users may always use a link from the system's part to another. Or after landing, it may not be reflected in a hurry, and suddenly request another service ... If the Web system does not have a good design structure, these annoying problems can be wrapped in you until you crash, or the system crashes. Even if you are hard to get a few off, the post-maintenance work can be mad, or mad at other maintenance people! MVC (Model - View - Controller) mode The most important idea is that the service code is separated from the view code. It can effectively clear the system structure and reduce the difficulty of system complexity and maintenance. And Struts is implemented based on J2EE's web-form MVC mode! Struts was earliered as an integral part of the Apache Jakarta project. The founders of the project hopes through research, improvement, and improved Java Server Pages (JSPs), servlets, label libraries, and object-oriented technology levels. Struts This name is from the support metal rack used in the building and the old aircraft. Its purpose is to reduce the time to develop web applications with the MVC design model. You still need to learn and apply this architecture, but it will be able to complete some of them.
Second, Struts Introduction Struts IS is part of the Apache Jakarta project, which develops the open source of the web application with Java Servlet / JavaServer Pages technology. Framework. Struts has the following main functions: 1. Contains a Controller Servlet to send the user's request to the corresponding Action object. 2. JSP Free Tag Library and provides association support in the Controller Servlet to help developers create interactive form applications. 3. Provide a series of practical objects: XML processing, automatically handle JavaBeans property, international tips, and messages through Java Reflection APIs. The Struts project's goal is to provide an open source Framework for creating a Java web app. The Struts Framework core is a flexible control layer based on, for example, Java Servlets, JavaBeans, ResourceBundles, and XML, and standard technology for various Jakarta Commons packets. Struts provides its own controller components and integrates other technologies to provide models and views. For models, like most third-party software packages, such as Hibernate, Ibatis, or Object Relational Bridge, Struts, can combine with standard data connection technology, such as JDBC and EJB. For views, Struts works with JavaServer Pages, including JSTL and JSF.
Third, Struts's advantage Struts is the same as Tomcat, Turbine, etc., is open source software, which is a great advantage. Make developers more in-depth understanding of their internal implementation mechanisms. In addition, Struts's advantages are mainly concentrated in two aspects: taglib and page navigation. Taglib is the Struts tag library, flexible, which can greatly improve development efficiency. In addition, in addition to the current Domestic JSP developers, in addition to the common tags that come with JSP, we have rarely develop their own tags, maybe Struts is a good starting point. About page navigation, I think that will be a development direction in the future, in fact, doing so, make the system's context more clear. With a configuration file, you can grasp the contact between the entire system, which has a great advantage for later maintenance. Especially when another group of developers take over the project, this advantage is more apparent. Struts has gradually been used for commercial software, which is a very good J2EE MVC implementation. If your system is ready to adopt J2EE MVC architecture, then you may wish to consider Struts. Fourth, Struts Working Principle MVC is the abbreviation of Model-View-Controller, is a common design pattern. The MVC weakens the coupling between business logic interfaces and data interfaces, and makes view layers more varied. The working principle of MVC is shown below:
Struts is an implementation of MVC, which uses a part of the Servlet and JSP tag (belonging to J2EE specification) as an implementation. Struts inherits the features of the MVC and made changes and expansions according to the characteristics of J2EE. Struts works, as shown below:
Control: You can see that there is an XML file struts-config.xml, which is associated with Controller. In Struts, the Controller role in the MVC is a servlet called an ActionServlet. ActionServlet is a universal control component. This control component provides an entry point that processes all HTTP requests sent to Struts. It intercepts and distributes these requests to the appropriate action classes (these action classes are subclasses of the Action class). Additional control components are also responsible for popping an action frombean using the corresponding request parameters, and transmits the action class (usually called ActionBean). Action class implements core business logic, which can access Java Beans or call EJB. The last action class transmits the control right to subsequent JSP files, and the latter generates a view. All of these control logics use the struts-config.xml file to configure. View: Mainly by JSP Generation Page Complete View, Struts provides a rich JSP tag library: HTML, Bean, Logic, Template, etc., which helps separate performance logic and program logic. Model: The model exists in the form of one or more Java Beans. These beans are divided into three categories: Action Form, Action, JavaBean or EJB. Action Form is usually called FormBean, encapsulated user request information from Client, such as form information. Action is often called ActionBean, obtains the FORMBEAN from the ActionSevlet, takes out the relevant information in the FORMBEAN, and makes relevant processing, usually call Java beans or EJB. Process: In Struts, the user's request is generally named * .do as a request service name, all * .do requests are pointed to the ActionSevlet, the ActionSevlet, according to the configuration information in Struts-Config.xml, and the user requests to encapsulate the user as a specified name. FORMBEAN, and pass this FORMBEAN to the ActionBean of the specified name, and the ActionBean completes the corresponding business operation, such as file operation, database operation, etc. Each * .do has a corresponding FormBean name and an ActionBean name, which is configured in Struts-Config.xml. Core: The core of Struts is ActionSevlet, the core of ActionSevlet is struts-config.xml. V. Scope of Struts If you need to write a very simple application, and there is very little page, you should consider "Model 1", just use Server Pages. However, if you want to develop a more complex app, there are many pages, and you need to maintain frequently in the future, then Struts is not a wise choice. Also, if you want to mix the advantages of servlets and JSP to establish scalable applications, Struts is a nice choice.