J2ee
SummaryThis paper briefly introduces the development of Java EE Technology and its Application architecture, discusses the basic design idea of struts framework, analyzes the advantages of struts framework development system, and realizes the application of Struts framework technology with concrete projects.
Key WordsJ2ee;mvc;struts frame;
Introduction to Java EE
The Java EE is an open, a standards-based platform for developing, deploying, and managing N-tier, web-oriented, server-centric enterprise applications, using the Java 2 platform to simplify the application architecture of many complex issues related to the development, deployment, and management of multi-level enterprise solutions.
The Java-EE platform uses a multi-level distributed application model. This means that the application logic is divided into components based on functionality, and the different application components that make up the Java EE application are installed on different servers, which is determined by which level of application components belong to a multi-level Java EE environment. As shown in Figure 1, the Java EE application can be composed of three or four levels, Java EE Multi-level applications are generally considered to be three layers of application, because they are distributed in three different locations: client machines, Java server and database or back-end of the traditional system server. The three-tier architecture application is an extension of the standard client/server application architecture, which adds a multi-threaded application server between the client application and the background storage.
Java EE system includes JSP, Servlet, EJB, WEB service and many other technologies. The advent of these technologies provides a very competitive choice for Web application development in the e-commerce era. How to combine these technologies to form a stable framework to meet the needs of the project is a very important step in the project development process.
A successful software needs to have a successful architecture, but the establishment of software architecture is a complex and continuous improvement process, it is impossible for software developers to each different project to do different architectures, but always try to reuse the previous architecture, or develop the most common architectural solution, Struts is one of the popular architecture schemes based on Java EE, and other common architectures based on Java EE are turbine, realmothods and so on. This paper mainly discusses the application of struts frame technology.
the development of Java EE Application Architecture
In the development of the Java EE Application Architecture, the main experience is two major stages:
1, Model 1
Combining business logic, server-side processing and HTML in JSP pages, the display, business logic and Process control are realized in JSP pages, which can quickly complete Web application development. The disadvantage of this model: 1 is not conducive to application extension and update. 2 The combination of business logic and presentation logic is not abstracted and separated in JSP pages, which is not conducive to the reuse and alteration of the application system business.
2, Model 2
Represents a framework based on the MVC pattern. According to model 2,servlet processing data access and navigation flow, JSP processing performance. Model 2 enables Java engineers and HTML designers to work separately on the parts they are good at and responsible for. The change in part of Model 2 's application does not force other parts to change. HTML developers can change the look and feel of the program and do not need to change how the back-end servlet works. The application logic, processing process and display logic are divided into different component implementations. Make up for the shortage of Model1.
Struts Framework Technology
The Struts framework is based on the Model 2 architecture, which is the framework technology based on the MVC pattern. It is a free open source Web layer application framework with high scalability and a list of growing features. A front-end control component, a series of action classes, action mappings, utility classes for processing XML, automatic filling of server-side Java beans, Web Forms that support validation, internationalization support, generating HTML, and implementing presentation logic and templates compose the soul of struts. Figure 2 shows how the struts component works together.
The Actionservlet of Struts controls the navigation flow. Other struts classes, such as action, are used to access business logic classes. When Actionservlet receives a request from the container, it uses the URI (or path "paths") to determine which action will be used to process the request. An action can validate input and access the business layer to retrieve information from a database or other data service.
To update the database for validation input or to use input, the Action needs to know what is being submitted. Instead of forcing each action to crawl the values from the request, the Actionservlet binds the input to the JavaBean. The input bean is a subclass of the Struts Actionform C class. Actionservlet can decide which actionform,action to use by looking up the requested path and also by the same method. Each action must be answered with an HTTP response. Typically, the Struts Action does not process the response information itself, but instead forwards the request to another resource, such as a JSP page. Struts provides a Actionforward class for storing the path of a page as a logical name. When the business logic is complete, the Action selects and returns a Actionforward to the servlet. The Servlet then calls the page to complete the response using the path stored in the Actionforward object.
Struts binds these details to a Actionmapping object. Each actionmapping relative to a specific path. When a path is requested, the Servlet queries the Actionmapping object. The Actionmapping object tells the servlet which actions, actionforms, and actionforwards will be used.
All of these details, about action, Actionform, Actionforward, actionmapping, and much more, are defined in the Struts-config.xml file. Actionservlet reads this configuration file at startup and creates a configuration object database. At run time, the Struts application is based on the configuration object created by the file, not the file itself.
An example of application design based on struts framework
This paper takes the software leasing module in the project "Development of networked manufacturing ASP platform for foundry industry" as an example to illustrate how to design a Web application based on the struts framework. In this module, after the user legally landing the site, you can choose the type of software to be rented and the function of the software module, confirm the information submitted to the server, users will receive the system given the login password, users can access the Web site, online use of rental software, the implementation of business hosting.
According to the requirements of the project analysis, to determine the system must have the performance: 1 good interactivity: The work content of a considerable part of the human-machine communication, which requires system interaction is stronger. 2 Good scalability: The content and form of the work has variability, requiring a good scalability of the system. 3 good maintainability: After the system put into use, mainly by the administrator to bear the system maintenance work, maintenance personnel irregular changes, which requires a strong system maintainability. 4 has a better cross-platform: Users may use a variety of different operating systems, and in order to adapt to future changes, the system should have a better cross-platform. Based on the above four points, in the development of software leasing modules, the use of Java-EE programming environment, and the corresponding use of Java-EE customized struts framework.
To do project development based on the struts framework, the key is to have a good overall model, plan the system including which several modules, each module needs what kind of Formbean, JavaBean, all kinds of processing results through which JSP page to show, Configure the Struts-config.xml file at the same time. The design model of this system is shown in Figure 3.
Actionservlet accepts all HTTP requests and, depending on the contents of the configuration file, determines which action object to map the request to, there are two action objects in the system, corresponding to the login remote software (logonaction) and the System feedback password ( mailaction).
Logonaction first verifies that the user is logged in and redirects to the login page (logon.jsp) If there is no login, and then determines the next processing according to the request parameters, if the user has not chosen to rent the software, Then go to the Software Introduction leasing interface (QUERY.JSP), select the software or software that needs to be rented some modules, the submission of information, mailaction the server to the user to submit the password, the user received the password, log on to run the software.
If the user logs on to the software successfully, through the Actionforward in the configuration file Struts-config.xml, the leased software information of the user is read through the GetInfo object, then the JSP page is called to display the data in the bean. If it is to save the data information, then the Saveinfo object will keep the information in the Formbean in the database; if it is to modify the information, the Modifyinfo object will keep the modified information in the database in the Formbean; if you are deleting data information, The Deleteinfo object is called to remove the information persisted in the Formbean from the database.
The system has been designed so that the user interface and data processing have been completely separated, plus the use of custom tags in the JSP page, so that the page does not have Java script code, so that the design of the Web interface and back-end program writing has a clear line, easy to develop the division of the team, and maintenance is also very convenient.
Concluding remarks
Struts is a very good Java based MVC application framework, although from the official release to now only two years, but it has been increasingly used on the enterprise platform, many large Web sites have successfully applied the struts framework. On the basis of summarizing the struts frame technology and its working principle, combining the project of "Networked manufacturing ASP Platform for foundry industry", this paper puts forward the design idea of online leasing module, which provides a reference for better application of struts framework in the future.