Objective
Recently began to learn some of the Java backend knowledge, a lot of do not understand or to learn the record here, I hope that their learning at the same time can help some others, if there is anything wrong or need to add to the welcome message, I will continue to learn and modify!
Label
First, Spring
Spring is a powerful framework that solves many of the problems that are common in the development of Java EE. Spring provides a consistent approach to managing business objects and encourages the good habit of injecting programming to interfaces rather than classes. The schema base of spring is based on the inversion of control container that uses the JavaBean property. However, this is only part of the complete Picture: Spring is unique in using the IOC container as a complete solution to all architectural layers. Spring provides a unique data access abstraction, including a simple and efficient JDBC framework, which greatly improves efficiency and reduces possible errors. Spring's data Access architecture also integrates hibernate and other O/R mapping solutions. Spring also provides a unique transaction management abstraction that provides a consistent programming model across a variety of underlying transaction management techniques, such as JTA or JDBC transactions. Spring provides an AOP framework written in the standard Java language that provides POJOs with declarative transaction management and other enterprise transactions-if you need it-to implement your own aspects. This framework is powerful enough to allow applications to throw away the complexity of EJBS while enjoying the critical services associated with traditional EJBS. Spring also provides a powerful and flexible MVC web framework that can be integrated with IOC containers.
Second, STRUCTS
Struts is an MVC framework based on the Sun EE platform, which is implemented mainly by servlet and JSP technology. Because struts can fully meet the needs of application development, easy-to-use, agile and rapid, over the past year has been a considerable concern. Struts consolidates Servlets, JSPs, custom tags, and information resources into a single, unified framework that developers use to develop without having to code their own full set of MVC patterns, saving time So struts is a very good application framework.
Third, Hibernate
Hibernate is an open-source object-relational mapping framework that provides JDBC with a very lightweight object encapsulation that allows Java programmers to manipulate databases at will using object programming thinking. Hibernate can be applied to any JDBC application, both in Java client applications and in servlet/jsp Web applications, and most revolutionary is that hibernate can replace CMP in the EE architecture of the EJB application. The task of achieving data persistence. , hibernate can be used to replace CMP in the Java EE architecture of EJB, and to accomplish the task of data persistence. Mapping is very simple, is the map of the page, do more practice will be.
Java three frameworks are used to make Wen applications. Struts is primarily responsible for presentation layer display spring uses its IOC and AOP to handle the control business (responsible for database operations) Hibernate is primarily the persistence of data to the database When using the JSP servlet to do Web page development, there is a mapping file with Web. XML, there is a mapping tag is used to do file mapping. When you enter the URL address in the browser, 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, so the page name is casually written, random name, regardless of your up. php.jsp. Do or anything else that corresponds to this Java file, what the code in this Java file does, what to do, whether to display a sentence or connect to a database or jump to another page, and so on, this Java file encapsulates the data into a secure and manageable role. In fact, this Java file compiled is a. Class of a bytecode file, there is not a similar HTML embedded tags and code page file. The difference between him and the JSP file is that the JSP embeds the code in the HTML tag. And the commit name in the action of the servlet or the HTML form in struts corresponds to a Java file, and struts is generally. Do, which is mapped as above.
Detailed description of the SSH framework
First of all,SSH is not a framework, but a multi-framework (struts+spring+hibernate) Integration , is now a popular web application open-source Integration Framework for the construction of flexible, A multi-tiered Web application that is easy to scale.
The systems that integrate the SSH framework are divided into four tiers: presentation layer, business logic layer, data persistence layer, and Domain module layer (entity layer).
Struts, as the overall infrastructure of the system, is responsible for the separation of MVC, controlling the business jump in the model part of the struts framework, and supporting the persistence layer with the Hibernate framework . Spring, on the one hand , is a lightweight IoC container that is responsible for locating, locating, creating, and managing dependencies between objects and objects, on the other hand, enabling Struts and Hibernate to work better.
The basic business process for building a system by SSH is:
1, in the presentation layer, first through the JSP page interactive interface, responsible for transmitting requests (request) and receive response (Response), and then struts according to the configuration file (Struts-config.xml) Delegate the request received by Actionservlet to the appropriate action handler.
2. in the business layer, the spring IOC container that manages the serviced component is responsible for providing the business model component to the action and the component's collaboration Object data Processing (DAO) component to complete the business logic and to provide transaction processing, Buffer pools and other container components to improve system performance and ensure data integrity.
3 . In the persistence layer, it relies on Hibernate's object mapping and database interaction, processing the data requested by the DAO component, and returning the processing result.
The above development model not only realizes the complete separation of the view, controller and model, but also realizes the separation of the business logic layer and the persistence layer. This way, no matter how the front-end changes, the model layer requires little change, and the database changes will not affect the front end, greatly improving the reusability of the system. And because of the small coupling between different layers, it is advantageous to the team members to work in parallel, greatly improving the development efficiency.
Let's take a look at the three frameworks that make up SSH
First, Spring
1. What is Spring?
In short, spring is a lightweight control inversion (IoC) and aspect-oriented (AOP) container framework.
2. Features of Spring
Specific self Baidu Bar
All of these features of spring enable you to write cleaner, more manageable, and easier-to-test code
3. Why use Spring?
The above features of spring allow developers to use basic javabean to accomplish things that were previously only possible by EJBS. However, the use of spring is not limited to server-side development. From the standpoint of simplicity, testability, and loose coupling, any Java application can benefit from spring.
Second, Struts
1. What is struts?
Using Java servlet/jsp Technology, it realizes the application framework of MVC design pattern based on Java eeweb application, and it is a classic product in MVC Classic design pattern.
2, the core composition of Struts1
In Struts1, a Servlet named Actionservlet acts as the controller, and forwards the view according to the configuration file that describes the struts-config.xml of the model, view, and Controller counterpart (view) Request, assemble the response data model.
In the model part of the MVC, it is often divided into two main subsystems (the internal data state of the system and the logical action of changing the data state), the two conceptual subsystems correspond to the Actionform and action two in Struts 1 respectively. Here, Struts 1 can be combined with a variety of standard data access technologies, including Enterprise Java Beans (EJB), JDBC, and JNDI.
In the view side of Struts 1, in addition to using standard JavaServer Pages (JSP), there are a number of tag library uses available, as well as integration with other presentation Layer component technologies (products), such as Velocity templates,xslt such as
By applying the Struts framework, end users can place most of their concerns in their own business logic (Action) and the mapping relationship configuration file (Struts-config.xml).
3, the basic implementation process of STRUTS1
See the basic work flow of struts
4. What is Struts2
Struts 2 is the next generation of struts and is the new Struts 2 framework that was combined with struts 1 and webwork technology. Its new Struts 2 architecture differs greatly from the architecture of struts 1. Struts 2 takes the webwork as the core and uses the interceptor mechanism to process the user's request, so that the business logic controller can be completely detached from the SERVLETAPI, so struts 2 can be understood as the webwork of the new product
5. STRUT2 Architecture
Analytical:
When the Web container receives the request (HttpServletRequest) It passes the request to a standard filter chain including the process (Actioncontextcleanup) filter, and then passes through the other filters (Sitemesh, etc),
Next you need to call the Filterdispatcher core controller, and then it calls Actionmapper to determine the request that Action,actionmapper returns a Actionmaping object that collects the action details.
Next Filterdispatcher delegate control to Actionproxy,actionproxy call Configuration Manager (ConfigurationManager) to read configuration information (Struts.xml) from the configuration file. The Actioninvocation object is then created, and Actioninvocation invokes the configured interceptor (Interceptor N) in turn before invoking the action. Once the result of the execution returns the result string actioninvocation is responsible for finding the result string corresponding to (result) and then executing this result will call some template (JSP)
To render the page, after which the Interceptor (Interceptor N) responds to the last response (the reverse of the order and the Action Execution) (HttpServletResponse) The filters and (core controllers) (Filterdispatcher) configured in Web. XML are returned.
6. Why use struts?
First, Struts is an implementation of MVC, which uses servlets and JSP tags (which belong to the Java EE Specification) as part of the implementation. Struts inherits the characteristics of MVC and makes corresponding changes and expansions according to the characteristics of the Java EE, weakening the coupling between the business logic interface and the data interface, and making the view layer more changeable.
In addition, struts has a page navigation function, which makes the system's context clearer. Through a configuration file, you can grasp the connection between the parts of the whole system, which is of great benefit to the later maintenance. This is especially true when another group of developers took over the project.
7. The difference between Struts1 and Struts2
See "Struts1 and Struts2"
Third, Hibernate
1. What is Hibernate?
Hibernate is an open-source object-relational mapping framework that provides JDBC with a very lightweight object encapsulation that allows Java programmers to manipulate databases at will using object programming thinking. Hibernate can be applied to any JDBC application, both in Java client applications and in servlet/jsp Web applications, and most revolutionary of all, hibernate can replace CMP in the EE architecture of the EJB application. The task of achieving data persistence
2.Hibernate Core composition
It's not going to unfold.
3.Hibernate Basic execution Process
Why use Hibernate?
1. The code for JDBC access to the database is encapsulated, which greatly simplifies the tedious repetitive code of the data access layer.
2, Hibernate is an excellent ORM implementation. He simplifies the coding of the DAO layer to a large extent, freeing the software developers from the extensive programming of the same data persistence layer, and making the development more object-based.
3, good transplant, support a variety of databases, if you change a database as long as the configuration file configuration can be changed, do not change hibernate code.
4, support transparent persistence, because hibernate operation is pure (Pojo) Java class, did not implement any interface, no intrusion. So it's a lightweight framework.
Finally attach the example of SSH1 and SSH2 frame, click to download
SSH1 Frame Build Example (Spring2+struts1+hibernate3) with older versions, see the code for comments
SSH2 Framework Construction Example (spring3.2+strust2.3.4+hibernate4.2) all with the latest version, see the code in the comments
Development environment Construction, refer to another blog
"Win7" + Eclipse (+ tomcat7) + JDK7 (64) Development environment configuration
[HTML] View plain copy
- Some notes:
- Ask for the code of the mailbox, I have basically sent out, if there is a leak, please contact me.
- Or you want to go to the csdn download page to download. If the speed is slow, you can go here http://pan.baidu.com/s/1eQh7FXo
- Development environment configuration. http://blog.csdn.net/shan9liang/article/details/8807784
- In the war, find Application-common.xml. Modify the data source to specify your own database. After the project is deployed, the table is automatically mapped.
- <!--with data sources--
- <Bean id= "dataSource" class="Org.apache.commons.dbcp.BasicDataSource "
- destroy-method="Close">
- <property name= "driverclassname" value="Oracle.jdbc.driver.OracleDriver" />
- <property name="url" value="Jdbc:oracle:thin: @localhost: 1521:orcl" />
- <property name= "username" value= "ssh" />
- <property name= "password" value= "ssh" />
- </Bean>
- The above is the configuration of Oracle.
- If you are using a different database, in the Lib directory, add the driver package. and modify the data source.
- It is strongly recommended that:
- Https://code.csdn.net/shan9liang/tgb
- This is in CSDN code managed, using SSH to build an attendance management system, MAVEN project, than the original one more standardized, recommend this, and I will continue to update, gradually join various mainstream framework, believe me.
- 。 But not the Eclipse project, you need to import eclipse by hand, and have recently liked to use IntelliJ. It is recommended to use Git clone directly.
Also attached is a Web site for the Eclipse build SSH (struts2+spring3+hibernate3) Framework Project Tutorial:
http://blog.csdn.net/yeohcooller/article/details/9316923
SSH framework in Java