In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is the flow of object invocation in the SSH framework". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the flow of object invocation in the SSH framework".
SSH is not a framework, but the integration of multiple frameworks (struts+spring+hibernate). It is a popular open source integration framework for Web applications, which is used to build flexible and easy-to-expand multi-tier Web applications.
The system integrating SSH framework is divided into four layers in terms of responsibility: presentation layer, business logic layer, data persistence layer and domain module layer to help developers build Web applications with clear structure, good reusability and easy maintenance in a short period of time. Struts is used as the overall infrastructure of the system, responsible for the separation of MVC, in the model part of the Struts framework, control business jump, use the Hibernate framework to support the persistence layer, Spring to manage, manage struts and hibernate.
The system of SSH framework is based on MVC. Struts is a good MVC framework, and the main technologies are Servlet and Jsp. Struts's MVC design pattern can make our logic very clear and let us write a clear hierarchy of programs. Development based on Struts can simplify the development difficulty and improve the development efficiency.
Spring provides a consistent approach to managing business objects and encourages the injection of good habits for programming interfaces rather than classes to maximize decoupling of our products.
Hibernate is used to persist data and provides fully object-oriented database operations. Hibernate encapsulates JDBC very lightweight, which makes it very easy to deal with relational databases.
In a Struts+Spring+Hibernate system, the flow of calls between objects is as follows:
Struts-- > Spring-- > Hibernate
JSP-- > Action-- > Service-- > DAO-- > Hibernate
For example:
Configuration file bean.xml hibernate.dialect=org.hibernate.dialect.MySQL5Dialect hibernate.hbm2ddl.auto=update hibernate.show_sql=false hibernate.format_sql=false for 1.Spring Site/sambloger/domain/Users.hbm.xml site/sambloger/domain/Blog.hbm.xml site/sambloger/domain/Category.hbm.xml site/sambloger/domain/Comment.hbm.xml Configuration file struts.xml / bloglist.jsp for 2.Struts / displayBlog.jsp / notelist.jsp / getBlog 3.Hibernate one of the configuration files: The roles and benefits of the Spring framework:
The Spring framework provides a container that can manage the components of the application, and also provides IoC and AoP mechanisms to decouple the components, improve the flexibility of the program structure, and enhance the maintainability and expansibility of the system.
In SSH integrated development, Spring is used to manage Service, DAO and other components, and IoC mechanism is used to realize low-coupling calls between Action and Service,Service and DAO. Using AoP mechanism to achieve transaction management, as well as the cut-in of common functions.
The function is integration, and the advantage is decoupling.
Operation concurrency processing in Hibernate (optimistic lock and pessimistic lock)
The Hibernate framework can use the lock mechanism to solve the concurrency of operations.
a. Pessimistic lock
When the data is queried, a lock is added to the data. In this way, other users are not allowed to perform delete or change operations. When the occupied transaction ends, the lock is released automatically.
Hibernate uses database locking mechanism to realize pessimistic lock control.
Disadvantages: synchronize concurrent user operations and deal with them one by one. When a user takes a long time to process, the efficiency will be relatively low.
b. Optimistic lock
It is allowed to update the submission at the same time, but the fastest will succeed and the slow will fail.
Append a field value to the record and use that field value as the version. When the first submitter submits, the value of the version field is automatically raised, so that other users will find that the version is lower than the current version of the database record, so the exception failed.
Features: allow users to deal with at the same time, but only one success, other failures, prompted in an abnormal way.
SSH workflow
a. Start the server, load the project and web.xml.
(instantiate components such as Lisener,Filter, create Spring containers and Struts2 controls)
b. The client sends requests, and all requests enter the Struts2 controller. The controller handles the request separately according to the type of request.
(action request, * .action will go into struts.xml to find the configuration.
For other requests, * .jsp will directly call the request resource to generate response information)
The c.Struts2 controller invokes an Action object processing based on the configuration.
Integration method 1: give the Action to the Spring container
(the Action object provided by the struts2-spring-plugin.jar plug-in
StrutsSpringObjectFactory is responsible for getting it from the Spring container)
Integration method 2: place Action outside the Spring container
(the Action object provided by the struts2-spring-plugin.jar plug-in
StrutsSpringObjectFactory is responsible for creating it, then looks in the Spring container for a Bean object that matches the Action property, and injects it into the Action object. (name matching rule is used by default)
The d.Struts2 controller performs defaultStack interceptor, Action object, Result and other component processing.
e. When executing the execute business method of Action, it is called using Spring's IoC mechanism if Service or DAO is used.
f. Execute Result to generate response information, and perform subsequent interceptor processing
g. The response information is output.
Thank you for your reading, the above is the content of "what is the flow of object invocation in SSH framework". After the study of this article, I believe you have a deeper understanding of what the process of object invocation in SSH framework is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.