The advantages and disadvantages of framework learning framework

Source: Internet
Author: User

The advantages of struts are:

1. Implement the MVC pattern with a clear structure that allows developers to focus only on the implementation of the business logic.

2. There is a rich tag can be used, struts of the tag library (Taglib), if flexible to use, it can greatly improve the development efficiency. In addition, for the current domestic JSP developers, in addition to the use of JSP comes with common tags, rarely develop their own tags, perhaps struts is a good starting point.

3. Page navigation. Page navigation will be a future development direction, in fact, to do so, so that 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. Support i18n

Disadvantages:

First, go to the presentation layer, you need to configure forward, every time to the presentation layer, I believe most are directly to the JSP, and related to the steering, need to configure forward, if there are 10 display layer of the JSP, need to configure 10 struts, but also does not include sometimes directories, file changes, Need to re-modify the forward, note that each time the configuration is modified, it is required to redeploy the entire project, and the server such as Tomcat must restart the server, if the business changes frequently complex systems, such operations are simply unthinkable.

The action of Struts must be a thread-safe way, it only allows one instance to handle all requests, so all the resources that the action uses must be synchronized uniformly, which raises the thread-safety problem.

Third, the test is not convenient. Each of struts's actions is coupled to the web layer so that its tests depend on the Web container and unit tests are difficult to implement. However, there is a junit extension tool that struts testcase can implement for its unit testing.

Iv. types of conversions. The Formbean of struts takes all the data as a string type, which can be converted using the tool commons-beanutils. However, it is converted at the class level, and the type of conversion is not configurable. It is also very difficult to return the error message to the user when the type is converted.

V. The dependency on the servlet is too strong. Struts must rely on servletrequest and servletresponse when handling action, all of which are not able to get rid of the servlet container.

Vi. front-end expression language aspects. Struts integrates Jstl, so it uses the JSTL expression language primarily to get data. But Jstl's expression language is weak in terms of collection and indexed properties.

Vii. control of action execution is difficult. Struts creates an action, which can be very difficult if you want to control the order in which it is executed. You'll even have to write the servlet again to implement your functional requirements.

Eight, the action to perform before and after the processing. Struts handles action as a class-based hierarchies, which makes it difficult to operate before and after action processing.

Nine, the incident support is not enough. In struts, it is actually a form form that corresponds to an action class (or Dispatchaction), in other words: in struts it is actually a form that only corresponds to one event, and struts is called the application event, Application events is a coarse-grained event compared to the component event.

Struts important Form Object Actionform is an object that represents an application that contains at least a few fields that are input fields in a JSP page form, because a form corresponds to an event, so When we need to refine the event granularity to these fields in the form, that is, when a field corresponds to an event, simply using struts is less likely, and of course it can be done by combining JavaScript.

2 . Advantages and disadvantages of Hibernate:

Advantages:

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 used in any application where JDBC is available, both in Java client applications and in servlet/jsp Web applications, the most revolutionary Hibernate can be used to replace CMP in the Java EE architecture of EJB application, and to accomplish the data Persistence task. Most development agencies often take the creation of their own separate data persistence layer. Once the underlying data structure changes, the cost of modifying the rest of the application to accommodate this change is enormous. Hibernate fills this gap in a timely manner, providing an easy-to-use, efficient object-relational mapping framework for Java applications. Hibernate is a lightweight persistence framework with a very rich function.

A. hibernate uses the Java reflection mechanism instead of the bytecode enhancer to achieve transparency .

B. Hibernate performs very well because it is a lightweight framework with excellent mapping flexibility.

C. It supports a variety of relational databases, ranging 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), however, Hibernate mitigates these risks with its powerful development momentum. Other open source persistence frameworks also have some, but none have the market impact of Hibernate.

3 . Advantages and disadvantages of Spring framework

Advantages

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

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 using JDBC or O/R mapping Products

Spring does allow you to solve your problem with the simplest possible solution. And that's a lot of value.

disadvantage: The JSP to write a lot of code, the controller is too flexible, missing a public controller.  

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: A model exists in the form of one or more javabean. 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.

Hibernate's main interface:

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.

Session Interface The 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.

Configuration Interface The purpose of the configuration interface is to configure Hibernate and start it . 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.

Query and Criteria interface The query interface makes it easy to make queries against 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 , notably that the query interface is also lightweight and cannot be used outside of 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.

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.

The advantages and disadvantages of framework learning framework

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.