Three main frames: struts+hibernate+spring
The three main frameworks of Java are used to make Wen applications.
Struts is primarily responsible for displaying the presentation layer
Spring uses its IOC and AOP to handle the control business (responsible for the operation of the database)
Hibernate is primarily data persistence to the database
And then use the JSP servlet to do web page development when there is a mapping file of XML, there is a mapping tag is used to do file mapping. When you enter the URL in the browser to know, the file will be based on the name you write to a Java file, according to the content written in the Java file displayed in the browser, is a Web page.
A. Struts framework: Struts is open source software. Struts is used to help us reduce the time it takes to develop Web applications using the MVC design model. Struts is a good choice if we want to mix the benefits of Servlets and JSPs to build scalable applications.
1. Process: After the server starts, read the Struts-config.xml file contents to memory according to Web. XML Load Actionservlet.
2. Architecture: Struts provides the corresponding components for both Model,view and controller. Actionservlet, this class is the core controller of struts and is responsible for intercepting requests from users.
Model part: Composed of JavaBean, Actionform used to encapsulate the user's request parameters, encapsulated as Actionform object, the object is Actionservlet forwarded to the Action, The action processes the user's request based on the request parameters inside the Actionfrom. The JavaBean encapsulates the underlying business logic, including database access.
View section: This part is implemented by JSP. Struts provides a rich library of tags that can reduce the use of scripts through a tag library, and a custom tag library enables effective interaction with the model and adds real-world functionality. The corresponding JSP part.
Controller components: Controller components are composed of two parts-the system core controller, the business logic controller. System core Controller, corresponding to the Actionservlet. The controller is provided by the struts framework and inherits the HttpServlet class, so it can be configured as a callout servlet. The controller is responsible for intercepting all HTTP requests and then deciding whether to transfer to the business logic controller based on user requests. The business logic controller, which is responsible for processing user requests, does not have the processing power, but calls model to complete processing. Corresponds to the action section.
Two Spring Framework
Spring is a powerful framework that solves many of the problems that are common in the development of Java EE. Springle provides a consistent approach to managing business objects and encourages the injection of programming to interfaces rather than the good habit of becoming a class. The schema base of spring is based on the inversion of Control container that uses the JavaBean property. However, spring is unique in using the IOC container as a complete solution for building play that focuses on all architectural layers. Spring provides a unique data management abstraction that includes a simple and efficient JDBC framework that greatly improves efficiency and reduces possible errors. Spring's data Access architecture also integrates hibernate and other O/R mapping solutions.
Three Hibernate framework
Hibernate is an object-relational mapping framework for open source code, and the Philadelphia Lightweight object encapsulation is awakened to JDBC, allowing Java programmers to manipulate databases with arbitrary objects. Hebernate can be applied to any JDBC application, either in Java client programs or in servlet/jsp Web applications, and hibernate can replace CMP in the EE architecture of the EJB application. The task of achieving data persistence
Hibernate has a total of 5 core interfaces: Session, sessionfactory, Transaction, query, and configuration. These 5 core interfaces will be used in any development. Through these interfaces, you can not only access persistent objects, but also enable transaction control. These five core interfaces are described separately below.
1. Session interface: A CRUD operation that is responsible for executing a persisted object (the task of crud is to complete the communication with the database, including many common SQL statements. )。 However, it is important to note that the session object is non-thread-safe. At the same time, Hibernate's session differs from the HttpSession in JSP applications. When the term "session" is used, it is actually referring to the session in Hibernate, and later the HttpSession object is called the user session.
2. Sessionfactory interface: Responsible for initializing hibernate. It acts as a proxy for the data storage source and is responsible for creating session objects. The factory model is used here. It is important to note that Sessionfactory is not lightweight, because in general, a project typically requires only one sessionfactory, and when you need to manipulate multiple databases, you can specify a sessionfactory for each database.
3. Configuration Interface: Responsible for configuring and starting Hibernate, creating Sessionfactory objects. During Hibernate startup, the instance of the configuration class first locates the map document location, reads the configuration, and then creates the Sessionfactory object.
4. Transaction interface: Responsible for transaction-related operations. It is optional, and developers can also design their own underlying transaction-processing code.
5. Query and Criteria interface: responsible for executing various database queries. It can be expressed in either the HQL language or the SQL statement.
Struts, Hibernate, and spring are common keys in our Java development, and they provide the most appropriate solution for different scenarios. But do you know how these well-known frameworks were originally created?
We know that traditional Java Web applications are implemented using Jsp+servlet+javabean, which implements the most basic MVC layering, which divides the program structure into several layers, the JSP that is responsible for the foreground display, The servlet responsible for the process logic control and the JavaBean responsible for the data encapsulation. However, this structure still has problems: such as JSP pages need to use <%%> symbols embedded in a lot of Java code, resulting in a confusing page structure, servlet and JavaBean responsible for a large number of jump and computation work, coupled tightly, the program reusability is low and so on.
Struts
In order to solve these problems, the struts framework has emerged, it is a perfect MVC implementation, it has a central control class (a servlet), for different business, we need an action class responsible for page jump and background logic operation, One or several JSP pages are responsible for the input and output display of the data, and a form class is responsible for passing data between the action and the JSP. A set of tags provided by the Struts framework can be used in JSPs, as simple as HTML tags, but it can be done with very complex logic. There is no need for a line <%%> enclosing Java code in this JSP page.
But all the arithmetic logic put in the struts action will make the action class reusability low and logical confusion, so usually people will divide the entire Web application into three layers, struts is responsible for the display layer, it calls the business layer to complete the operational logic, the business layer calls the persistence layer to complete the database read and write.
Using the JDBC connection to read and write the database, our most common is to open the database connection, the use of complex SQL statements to read and write, close the connection, the obtained data needs to be transformed or encapsulated after the rumor, this is a very cumbersome process.
Hibernate
There is a hibernate framework, which requires you to create a series of persistent classes, each class of properties can be easily seen as a database table of the properties of one by one corresponding, of course, you can also implement the relational database of the various forms of the corresponding correlation. When we need to do this, we don't have to focus on database tables. We do not have to go to a row of query database, only need to persist the class to complete the function of the increase and deletion check. Make our software development truly object-oriented, rather than code that is confusing. My feeling is that using hibernate reduces the programming amount by 80% compared to the JDBC approach.
Now we have three layers, but what is the call between each layer? For example, the struts of the display layer need to invoke a business class, it needs new business class to come out, then use it, the business layer needs to invoke the class of the persistence layer, and it needs to use the new persistence layer class. Invoking each other in this new way is the embodiment of the worst design in software development. Simply put, it is the caller who relies on the callee, which forms a strong coupling, and if I want to reuse a class elsewhere, the other classes that the class relies on are also included. The program becomes chaotic, with each class relying on each other to invoke each other, with a very low degree of reusability. If a class has been modified, many of the classes that depend on it will be implicated. To do this, the spring framework appears.
Spring
Spring's role is to fully decouple the dependencies between classes, and if a class depends on anything, it is an interface. As for how to implement this interface, this is not important. As soon as you get a class that implements this interface, you can easily inject the implementation class into the class that invokes the interface through an XML configuration file. This dependency between all classes is completely superseded by the configuration file. So the core of the spring framework is the so-called dependency injection and control inversion.
Now the structure is, struts is responsible for the display layer, hibernate is responsible for the persistence layer, spring is responsible for the middle business layer, this structure is the most popular Java Web application architecture in the country now. In addition, because of the dependency injection and AOP (aspect-oriented programming) used by spring, this internal pattern is so good that spring itself implements an MVC framework that uses a dependency injection, called Spring MVC, and in order to handle things well, Spring integrates hibernate, enabling things to be managed from Hibernate's persistence layer to the business layer, which is more convenient and powerful to use.
The struts framework was started in 2000 and has been developed for more than 5 years, and the technology is quite mature, and the struts framework of the global Java development is a well-deserved king in the display layer technology. It has a large number of user groups and a good development team. This is also the majority of the domestic Java software companies to new employees basic requirements.
Java technology that you should master
When we choose Java in the technology line, we choose that you must continue to learn, always focus on the latest technologies, know them, see if they are right for you, and then learn to use them.
Java Basics:
Java principles and usage, including basic language, grammar knowledge, and APIs
Jsp+servlet,java the basics of web development
This can be a focus on the Java Development Foundation topic.
Server:
Principle, use and configuration of WebLogic
Tomcat: Lightweight Javaweb container, similar to WebLogic, simple, convenient, free, open source, but not EJB-enabled
JBoss: Similar to Tomcat, more powerful, EJB-enabled
It is necessary for these three application servers to have at least one of these.
Framework:
Struts, Spring, Hibernate
Tapestry: This is a new MVC framework, using component-based development, is the development trend of display layer technology.
Flex and Laszlo: The new display layer technology, which supports rich client applications, is currently the more advanced display technology.
The full name of EJB:EJB is Enterprise JavaBeans, which is the commercial application component technology in Java.
Java Web Development Peripheral Technologies:
HTML, Javascript, CSS, XML, XSLT, which are often used in development, should be mastered.
Development tools:
Dreamweaver, Eclipse, or jbuilder, PL/SQL
Database:
Oracle must be used, SQL Server mastered, and MySQL can be used while learning. DB2 that kind of thing do not learn, the domestic too little use.
Software:
You can understand UML design and use UML for simple design.
Three main frameworks of Java