Application development of Java EE based on hibernate and struts

Source: Internet
Author: User

Introduction

With the gradual maturation and perfection of Java technology, as a standard platform for enterprise-level application, the EE platform has made great progress. With the help of the many techniques included in the Java EE specification: Enterprise JavaBean (EJB), Java servlets (Servlet), Java Server Pages (JSP), Java message Service (JMS), Many application systems have been developed. However, there are some problems in the development of traditional Java EE application: 1 The contradiction between data model and logical model. The databases that are currently used are basically relational databases, Java is essentially an object-oriented language in which objects use SQL and JDBC to perform database operations while storing and reading, reducing the efficiency of programming and maintainability of the system; 2 The traditional Java-EE application is based on the heavy frame of EJB, This framework is suitable for developing large enterprise applications, but it takes a lot of time to develop and debug with EJB containers. In order to reduce the coupling of code and improve the development efficiency of the system, this paper proposes an application development strategy of Java EE based on Struts framework and hibernate framework.

Data persistence layer and Hibernate

Hibernate is a data persistence layer framework, a tool for implementing mapping between objects and Relationships (O/R Mapping), which is a lightweight object encapsulation for JDBC, allowing programmers to manipulate databases using object programming ideas. It provides not only a mapping from Java classes to datasheets, but also a mechanism for querying and restoring data. Using JDBC and SQL to manipulate the database, the use of hibernate can greatly improve the efficiency of the implementation. The hibernate framework defines the mapping relationship between Java objects and data tables in the form of a configuration file and, at a deeper level, interprets the relationship between the data tables as inheritance and inclusion between Java objects. By using the HQL statement to describe the complex relational algorithm in terms of object, it simplifies the query of data to a large extent, and accelerates the development efficiency. In Hibernate, there is a simple and intuitive API for executing queries on objects represented by the database. To create or modify these objects, you simply interact with them in your program, and then tell Hibernate to save. Thus, the business logic of a large number of encapsulation persistence operations is no longer required to write cumbersome JDBC statements, so that the data persistence layer is greatly simplified.

Implementing MVC architecture with struts

MVC (Model-view-controller), proposed by Trygve Reenskaug, was first applied to the SMALLTALK-80 environment and constituted the basis of many interaction and interface systems. According to the requirement of variability of interface design, MVC decomposes The composition of interactive system into three parts of model, view and controller.

Model is the internal abstraction of the logic of the problem that the software deals with is independent of the external display content and form, encapsulates the core data of the problem, the computational relation of logic and function, independent of the concrete interface expression and I/O operation. View displays information about the model data and the logical relationship and status and the specific form to the user. It obtains display information from the model, and can have several different display forms or views for the same information. A controller (Controller) is a process that handles user-software interaction. The responsibility is to control the propagation of any changes in the model, to ensure the interface between the models, to accept the input from the user, to feed the input to the model, to realize the calculation control of the model, and is to make the model and view coordinate the work of the parts. Usually one view corresponds to a controller. The separation of models, views, and controllers allows a model to have multiple display views. If a user changes the model's data through a controller of a view, all other views that depend on the data should reflect these changes. Therefore, whenever a data change occurs, the controller notifies all views of the change, causing the update to be displayed. This is actually a model of the change-propagation mechanism.

The struts framework was first shipped as part of the Apache Jakarta Project, inheriting the features of MVC and making changes and expansions based on the characteristics of Java EE. The struts framework is a good combination of Jsp,java Servlet,java bean,taglib technology. In struts, it is actionservlet that assumes the role of controller in MVC. The Actionservlet is a general-purpose control component. This control component provides an entry point for handling all HTTP requests sent to struts. It intercepts and distributes these requests to the corresponding action class (these action classes are subclasses of the action Class). Additionally, the control component is responsible for populating the action Form (Frombean) with the corresponding request parameters and passing it to the Action Class (Actionbean). The action class accesses the core business logic, that is, accessing the Java bean or invoking the EJB. The last action class passes control to the subsequent JSP file, which generates the view from the JSP file. All of these control logic is configured using the Struts-config.xml file. In the struts framework, the view is mainly completed by JSP Generation page, struts provides a rich JSP tag library, which facilitates the separation of performance logic and program logic. The model exists in the form of one or more Java beans. In struts, there are mainly three types of beans, namely ACTION,ACTIONFORM,EJB or Java beans.

The struts framework does not specifically define the implementation of the model layer, and in practice, the model layer is usually closely connected to the business logic and operates on the underlying data. The following describes a development strategy that introduces hibernate to the model layer of the struts framework and uses it for data encapsulation and mapping to provide support for persistence.

Related Article

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.