content:
1. Modeel 1 and Model 2 Introduction 2. Structure and Processing Process Introduction 3. Develop the work of the MVC system to do with the Struts framework. Example of a reference for reference
There is also a Java area:
Teaching tools and product code and components all articles practical skills
ZHAOCHENXI@vip.sina.com) December 2002. Model 1 and Model 2 Introduction We often mentioned in developing web applications is Model 1 / Model 2, then what does it mean? In fact, it is a description of different models that make up a web application using JSP technology. Here is a simple introduction to this concept. Model 1 In an example of establishing a web application using Java technology, due to the development of JSP technology, this soon that this easy to master and realize rapid development has become the main technique for creating web applications. The JSP page can be very easy to combine business logic (JSP: UseBean), the server processing process (JSP: scriplet), and HTML (), simultaneous display, business logic, and flow control simultaneously, so as can be quickly Complete application development. A lot of web applications now is made up of a set of JSP pages. This development model-centric development model we can call Model 1. Of course, this development model has a very advantage when conducting fast and small-scale applications, but from the perspective of engineering, it also has some shortcomings:
The implementation of the application is generally based on the process, a set of JSP pages implements a business process. If you want to make changes, you must modify multiple places. This is very disadvantageous to apply extensions and updates. Since the application is not built on the module, business logic and representation logic mixed in the JSP page did not perform abstract and separation. So very disadvantageous to the reuse and modification of the application system business. Considering these issues must adopt different design patterns when developing large web applications - this is the MODEL2 Model 2 Model 2 represents a MVC mode-based framework. MVC is a short written by Model-View-Controller. "Model" is the application's business logic (implemented by javabean, ejb component), "view" is the application's representation surface (generated by JSP page), "Controller" is a process control (generally a servlet) The application logic, processing procedure, and display logic are achieved by this design model into different components. These components can interact and reuse. This makes up for the shortcomings of Model 1. Model 2 has the advantages of componentization, making it easier to achieve development and management of large-scale systems, but developing MVC systems is more complicated than simple JSP development, it requires more time learning and master. At the same time, the introduction of new things will bring new problems (this reminds me of an article about "Automatic Calculation", which refers to the complexity of the system, resulting in higher complexity).
The application structure must be rethinked and designed based on the MVC component. It turns out that the application that can be implemented by establishing a simple JSP page now has become a designed and implementation process of multiple steps. All pages and components must be implemented in the MVC framework, so additional development must be performed. The MVC itself is a very complex system, so when using the MVC to implement a web application, it is best to choose an off-the-shelf MVC framework, which is developed under this, thereby obtaining a half-time effect. There are now many MVC frameworks available, because Struts have a complete document and relatively simple, so use it develops the MVC system or more convenient. 2. Struts Structure and Processing Process Introduction Struts is a project of Apache organizations, like other Apache organizations, and it is also an open source project. Struts is a better MVC framework for providing the underlying support for the development of the MVC system, which is the main technique of use of servlet, JSP, and Custom Tag Library. Getting its usage versions and specific information can be found at http://jakarta.apache.org website. The basic composition of the Struts framework is shown in the figure below: Figure 1 Struts UML
As a framework of MVC, both Struts provide corresponding components to Model, View, and Controller, corresponding to the UML map above, and see how they are combined.
Controller: The role of the controller is to accept requests from the client and select Perform the corresponding business logic and then send the response result back to the client. In Struts Controller function consists of an ActionServlet and an ActionMapping object in the figure: The core is an object ActionServlet for a servlet type, which is used to accept the client's request. The ActionServlet includes a set of configuration-based ActionMapping objects that implements a request to a specific MODEL section between an Action processor object. The Model section in the MVC system can be divided into two types-system internal states, and the action of changing the system status. Struts provides an Action and ActionForm objects for the Model section: All Action processor objects are subclasses of developers from Struts Action class. The Action processor object encapsulates the specific processing logic, calls the business logic module, and submits the response to the appropriate VIEW component to generate a response. The ActionForm component object provided by Struts, which can describe client form data by defining attributes. Developers can derive sub-objects from it, using the custom marker combination with Struts, which can achieve good packages and support for the client's form data, Action processor objects can read and write it directly, and no longer need Data interaction with the request, response object. Support for interaction between View and Model is implemented via the ActionForm component object. Struts typically recommends using a set of JavaBeans to represent the internal state of the system, and can use components such as Entity EJB and Session EJB according to the complexity of the system. System status. Struts recommends separating "what" and "how" (how to do "(business logic) when implementing. This can achieve the reuse of business logic. View: The View section in the Struts application is implemented through JSP technology. Struts provides custom tag libraries that can be used very well with these custom tags to interact with the MODEL part of the system, and the JSP form created by using these custom tags can implement mappings in the model section, completed Package for user data, while these custom tags also provide a variety of display functions such as template customization. The processing process of the Struts framework refers to the characteristics of the MVC system, and the Simple Struts component structure is shown in Figure 2. The Struts Controller ActionServlet handles the client request, and the request is mapped to the ACTION processor object with the configured actionMapping object. Action Processing Object Accesses Data, Processing, and Response Customer Request in Actionform, which also calls the bacan component of the background that encapsulates the specific business logic. The Action processor object notifies the Controller in accordance with the processing result, and the Controller performs the next process. Figure 2 Structure of the Struts framework
3. Using the Struts framework to develop MVC systems to do due to Struts has provided us with a very good MVC framework, we can greatly accelerate the speed of development when using Struts to develop MVC systems. A development process that can be used during development is as follows (from information 3):
Collect and define applications. Define and develop "Screen Display" requirements based on data acquisition and display. Define access paths for each "Screen Display". Define the connection between ActionMappings to build to the application business logic. Develop all support objects that meet the requirements of the "Screen Display". Based on the data properties provided by each "screen display" requirements to create the corresponding ActionForm object development Action object called by actionMApping. Develop application business logic objects (Bean, EJB, etc.). Create a JSP page corresponding to the ActionMapping design. Establish a suitable configuration file struts-config.xml, web.xml. Development / Test / Deployment When using the Struts framework, the development of each part mainly includes: Model section: Using JavaBean and EJB components, design, and implementing the system's business logic. Detect specific Action processing objects from Action depending on the request. Complete the "What to do" is to call the business component composed of beans. Create a package that implements a derived class of ActionForm to client form data. Controller section: Struts provides us with the implementation of the core control section. We only need to configure an actionMApping object View section: To use the ActionForm object in Model, we must create an HTML form with custom tags provided by Struts. Separate the user interface with the custom tag library provided by Struts to separate the application logic and display logic. The Struts framework establishes the contact between View and Model through these custom tags. Struts's custom tag also provides a lot of custom pages. At the same time, you need to edit two profiles: Web.xml and Struts-Config.xml. Configure the interaction between each module in the Struts system. Here, do some of these two profiles: Web.xml file configuration: web.xml in web applications is where to configure, which describes the system's Controller object. Increase the following tags in Web.xml
······
servlet>
Description: This servlet object is the Controller provided by Struts, and you can specify initialization parameters, such as support for system application properties.
servelt-mapping>
Description: Implement the URL information of the client request and the specific processing of the server-side specific processing.
taglib>
·······
Note: Adding a reference to the custom tag library used by the application provided by Struts. The configuration of the struts-config.xml file: Struts-config.xml is the relationship between Controller and MODEL. It describes the rules that control the request to the specific processing in Controller, and it also describes the data provided by the customer and the corresponding mapping relationship of the ACTIONFORM component. Added marked
form-beans>
Description:
Path = "/ login" TYPE = "LoginAction" Name = "loginform" INPUT = "/ login.jsp" ··· /> action-mappings> Description: The Struts User's Guide http://Jakarta.apache.org "Struts Tutorial" Author: Stephan Wiesner Home www.stephanwiesner.de Struts series http://www.onjava.com/onjava/open_source/ "Design Patterns" Gamma, etc. Four people about Zhao Chenxi, have been focused on server-side procedures, like programming with C and Java, great interest in new technologies, current personal interests on J2EE on the Open Source project. Hope and more enthusiasts communicate. Email: zhaochenxi@vip.sina.com