[Java] SSH Frame Note _s.s.h Framework respective pros and cons

Source: Internet
Author: User

The principles and advantages of struts.
How Struts Works
MVC is the abbreviation of Model-view-controller, which is a common design pattern. MVC weakens the coupling between the business logic interface and the data interface, and makes the view layer more varied. How MVC works, as shown in 1:
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. How struts works,
Views: The main JSP generated page completion view, struts provides a rich JSP tag library: html,bean,logic,template, which facilitates the separation of performance logic and program logic.
Control: In struts, assume the controller role in MVC is a servlet, called Actionservlet. 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 classes (which are subclasses of the action Class). The control component is also responsible for populating the action from (often referred to as Frombean) with the corresponding request parameters and passing it to the action class (often referred to as Actionbean). The action class implements the core business logic, which can access Java beans or invoke EJBs. The last action class passes control to the subsequent JSP file, which generates the view. All of these control logic is configured using the Struts-config.xml file.
Model: The model exists in the form of one or more Java beans. These beans fall into three categories: action Form, Action, JavaBean or EJB. The Action form is often referred to as Formbean, which encapsulates user request information from the client, such as form information. Action is often called Actionbean, obtaining Formbean from Actionsevlet, extracting relevant information from Formbean, and making related processing, typically invoking Java beans or EJBS.
Process: In struts, the user's request is typically *.do as the request service name, and all *.do requests are directed to Actionsevlet, Actionsevlet According to the configuration information in the Struts-config.xml, the user request is encapsulated into a formbean of the specified name, and the Formbean is passed to the actionbean of the specified name, and the corresponding business operations, such as file operations, are performed by Actionbean. Operation and so on. Each *.do has a corresponding Formbean name and Actionbean name, which are configured in Struts-config.xml.
Core: The core of struts is the core of Actionsevlet,actionsevlet is struts-config.xml.
Struts pros and cons
Advantages:
1. Open source software, to gain a deeper understanding of its internal implementation mechanism.
2.Taglib Tag Library, flexible use, can greatly improve the development efficiency.
3. Page navigation 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.
4. Provide exception processing mechanism.
5. Database Link Pool Management
6. The action of Struts must be Thread-safe, which allows only one instance to process all requests. So all the resources that the action uses must be synchronized uniformly, which raises the thread-safety issue.
Disadvantages:
Taglib is a great advantage for struts, but for beginners it requires a continuous learning process and even disrupts your web authoring habits, but when you get used to it, you think it's really great.
Struts divides MVC's controller into three, increasing the complexity of the system while gaining a clearer structure.
Actionforms is inconvenient and cannot be unit tested (Strutstestcase can only be used for integration)

The principles and advantages of spring
The real essence of spring is the beanfactory and AOP that its IOC pattern implements, and its ability to extend itself on this basis is somewhat superfluous.
What is IOC mode
Scalability and weight/lightness, who is the main architecture of the utility system?
Spring
It is an open source project and is currently very active, it is based on the framework of the IOC (inversion of control, reverse control) and AOP architecture multi-layer Java EE system, but it does not force you to have to use spring in every layer, because it is modular very well, Allows you to choose one of its modules according to your needs, it implements a very elegant MVC, provides a unified interface for different data access technologies, and the IOC makes it easy to implement bean assembly, provides concise AOP and implements Transcation managment Wait a minute
Advantages
A. Spring can effectively organize your middle-tier objects, whether or not you choose to use EJBS. If you just use struts or other framework,spring specifically designed for the Java EE API, focus on solving the remaining problems.
B. Spring can eliminate the overuse of singleton that is common in many projects. In my experience, this is a big problem, and it lowers the testability and object-oriented aspects of the system.
C. By processing a configuration file in a way that is consistent across applications and projects, spring eliminates the need for a variety of custom-formatted properties files. Ever wondered what magical property items or system attributes a class was looking for, and had to read Javadoc or even source code? With spring, you just need to look at the JavaBean property of the class. The use of inversion of control (discussed below) helped to accomplish this simplification.
D.? By minimizing the cost of programming interfaces rather than classes, spring can promote good programming practices.
E. Spring is designed so that applications created with it depend as little as possible on his APIs. Most business objects in a spring application are not dependent on spring.
F. Applications built using spring are easy to unit test.
G. Spring makes the use of ejbs an implementation choice, not an inevitable choice for application architectures. You can choose to use POJOs or local EJBS to implement the business interface without affecting the calling code.
H. Spring helps you solve many problems without using EJBS. Spring provides an alternative to EJBS that can be used in many Web applications. For example, spring can use AOP to provide declarative transaction management without passing through the EJB container, if you only need to deal with a single database and not even need a JTA implementation.
I. Spring provides a consistent framework for data access, whether it is using JDBC or O/R mapping products such as hibernate.
Spring does allow you to solve your problem with the simplest possible solution. And that's a lot of value.
Disadvantage: The number of users, the JSP to write a lot of code, the controller is too flexible, missing a public controller

The principles and advantages of hibernate.
Hibernate uses the following techniques in the Java EE architecture: JDBC, JTA, JNDI. Where JDBC is a basic layer that supports relational database operations, it is combined with jndi and JTA to make hibernate easy to integrate into the Java EE Application Server. Here, we won't discuss all the methods in the Hibernate API interface in detail, we'll just briefly talk about the features of each of the main interfaces, if you want to know more, You can view the source code of these interfaces in the Net.sf.hibernate child package in Hibernate's source package. Let's talk about all the main interfaces in turn: The core interface the following 5 core interfaces are used in almost any actual development. Through these interfaces, you can not only store and obtain persistent objects, but also be able to control transactions.
The session interface session interface is one of the most important interfaces for hibernate developers. In hibernate, however, the instantiated session is a lightweight class, and creating and destroying it does not consume a lot of resources. This is really important in the actual project, because in the client program, the session object may be created and destroyed continuously, if the session overhead is too large, it will adversely affect the system.
Sessionfactory interface Here is a design mode-Factory mode, the user program from the factory class Sessionfactory to get the session instance. What makes you wonder is that sessionfactory is not lightweight! In fact its designer's intention is to allow it to be shared throughout the application. Typically, a project usually requires only one sessionfactory, but when your project is working on multiple databases, you must specify a sessionfactory for each database. Sessionfactory actually played a buffer in hibernate, buffering hibernate's automatically generated SQL statements and some other mapping data, and buffering some data that might be reused in the future.
The configuration interface configures hibernate to be configured and started. During Hibernate startup, an instance of the configuration class first locates the location of the mapped document, reads the configuration, and then creates a Sessionfactory object.
The query and Criteria interface Query interface makes it easy for queries to be made on databases and persistent objects, which can be expressed in two ways: the HQL language or the SQL statement for the local database. Queries are often used to bind query parameters, limit the number of query records, and ultimately perform query operations. The criteria interface is very similar to the query interface, which allows you to create and execute object-oriented, standardized queries. It is important to note that the query interface is also lightweight and cannot be used outside the session.
Callback interface The Callback interface notifies hibernate to receive a notification message when some useful event occurs-for example, when a persistent object is loaded, stored, and deleted. In general, the callback interface is not required in a user program, but you might use it when you want to create an audit log in your project. The following is its policy interface:
· Generation of primary keys (Identifiergenerator interface)
· Native SQL language Support (dialect abstract class)
· Buffering mechanism (cache and Cacheprovider interface)
· JDBC Connection Management (ConnectionProvider interface)
. Transaction management (Transactionfactory, Transaction, and Transactionmanagerlookup interfaces)
· ORM policy (Classpersister interface)
· Property access Policy (PropertyAccessor interface)
· Creation of proxy objects (Proxyfactory interface)
Hibernate creates a default implementation for each of the mechanisms listed above, so if you just want to enhance the functionality of one of its policies, simply inherit the class, and there's no need to write code from scratch.
Hibernate runs in two environments: manageable and non-managed environments
· Manageable environments-this environment can manage resources such as pool resource management, such as database connection pooling and transaction management, security definitions. Some typical Java EE servers (JBoss, Weblogic, WebSphere) have implemented these.
· A non-managed environment-just provides some basic functionality, such as a servlet container environment like jetty or Tomcat.
Advantages:
Hibernate is a lightweight object encapsulation of JDBC, which is a stand-alone object persistence layer framework. Hibernate can be used wherever JDBC can be used, such as the database access code for Java applications, the implementation class for DAO interfaces, or even the code that accesses the database in BMP.
Hibernate is a framework that is closely related to JDBC, so hibernate compatibility and JDBC drivers have a certain relationship with the database, but the Java program that uses it has nothing to do with the app server, and there is no compatibility issue.
Hibernate cannot be used to compare directly to an entity bean, but only in the framework of the entire EE project. And even in the overall framework of software, Hibernate appears as a substitute for JDBC, not as a substitute for an entity bean.
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 use of JDBC.
Hibernate uses the Java reflection mechanism instead of the bytecode enhancer to achieve transparency.
Hibernate has a very good performance because it is a lightweight framework. The flexibility of the mapping is excellent.
It supports a variety of relational databases, from one-to-one to many-to-many complex relationships.
Disadvantage: It restricts the object model you are using. (for example, a persistent class cannot be mapped to more than one table).
Let me make a list of the frame structures I have listed n times:
The traditional architecture:
1) Session bean <-> Entity Bean <-> DB
To address the alternative architecture of performance barriers:
2) Session Bean <-> DAO <-> JDBC <-> DB
A schema that uses Hibernate to improve the development efficiency of the above architecture:
3) Session Bean <-> DAO <-> Hibernate <-> DB

The above 3 architectures are analyzed:
1. Memory consumption: The JDBC Architecture 2 is undoubtedly the most memory-saving, hibernate architecture is the second, EB Architecture 1 is the worst.
2, operating efficiency: If JDBC code write is very optimized, then the JDBC schema is the most efficient, but the actual project, this is almost impossible, which requires the programmer is very proficient in JDBC, using batch statements, adjust Preapredstatement batch Parameters such as size and fetch size, as well as the use of result set cache if necessary, and so on. In general, programmers can't do this. The Hibernate architecture therefore shows the fastest running efficiency. EB's architecture is far less efficient.
3, development efficiency: with JBuilder support and simple projects, EB architecture development efficiency is highest, JDBC second, hibernate is the worst. However, in large projects, especially when the persistent layer relationship mapping is complex, hibernate is surprisingly efficient, JDBC is second, and the EB architecture is likely to fail.

[Java] SSH Frame Note _s.s.h Framework respective pros and cons

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.