Struts
Struts is an MVC framework based on the sun J2EE platform. It is mainly implemented using Servlet and JSP technologies.
The Struts framework can be divided into the following four main parts, three of which are closely related to the MVC mode:
1. model is essentially an action class in struts (This will be discussed in detail later). developers can implement business logic through it, at the same time, the user request to the action through the Controller forwarding process is based on the configuration information described by the struts-config.xml file.
2. view is a complete set of JSP custom tag libraries that work with the Controller servlet. using them, we can quickly create an application system interface.
3. The controller is essentially a servlet that forwards client requests to the corresponding action class.
4. A bunch of sdks used for parsing XML files. Struts uses XML to describe how to automatically generate some JavaBean attributes, in addition, Struts also uses XML to describe the user prompt information in international applications (This achieves the multi-language support of the application system ).
Spring
Spring is a Lightweight J2EE application framework.
The core of spring is a lightweight container (container) that implements the IOC (inversion of control) mode container. Spring's goal is to implement a comprehensive integration framework, implement a combination of multiple child frameworks under the Spring framework. These child frameworks can be independent of each other, or they can be replaced by other framework schemes, spring hopes to provide a one-stop shop framework integration solution.
Spring will not specifically propose some sub-frameworks to compete with the existing opensource framework, unless it feels that the proposed framework has a better idea, for example, spring has its own MVC framework scheme, because it thinks there are many improvements to the existing MVC solution, but it does not force you to use the solution it provides, you can choose the framework you want to replace its sub-framework, for example, you can still integrate your struts framework in spring.
The core concept of spring is IOC, and the abstract concept of IOC is "dependency transfer". For example, "high-level modules should not depend on low-level modules, however, all modules must rely on abstraction. This is a manifestation of IOC. "implementation must depend on abstraction rather than abstract dependency implementation" is also a manifestation of IOC, "applications should not depend on containers, but containers serve Applications" is also a manifestation of IOC.
Benefits of spring's modularity
Spring can effectively organize your intermediate layer objects, whether or not you choose to use EJB. If you only use struts or other frameworks that contain J2EE-specific APIs, you will find that spring is concerned with the issues left behind.
. Spring can eliminate the excessive use of Singleton in many projects. Based on my experience, this is a major problem, which reduces the testability and object-oriented features of the system.
Spring can eliminate the need for custom files using various formats of attributes, and can be configured in a consistent way throughout the application and project. I was once confused that a specific class had to read javadoc or even the source code to find the keyword or system attribute of a phantom attribute? With Spring, you can easily see the JavaBean attribute of the class. The use of inverted control (discussed below) helps with this simplification. Spring can promote good programming habits through interfaces rather than classes, reducing the programming cost to almost zero.
. Spring is designed to minimize the reliance on its APIs for Applications created using it. Most business objects in spring applications do not depend on spring.
Applications built using spring are easy to perform unit tests.
. Spring makes the use of EJB an implementation choice, not an inevitable choice of the application architecture. You can use pojos or local ejbs to implement business interfaces without affecting the calling code.
. Spring helps you solve many problems without using EJB. Spring can provide an EJB replacement, which is suitable for many web applications. For example, spring can use AOP to provide declarative transactions instead of using EJB containers. If you only need to deal with a single database, you do not even need to implement JTA.
. Spring provides a consistent framework for data access, whether using JDBC or O/R mapping products (such as Hibernate ).
Spring does allow you to solve your problem through the simplest and most feasible solution. These features are of great value.
What can spring do?
Spring provides many features, so I will quickly display all of its main aspects in turn.
Task Description:
First, let's clarify the spring scope. Although spring covers many aspects, we already have a clear concept of what should be involved and what should not be involved.
Spring aims to make J2EE easy to use and promote programming habits.
Spring does not re-develop existing things. Therefore, in spring, you will find packages without logging, no connection pools, and no distributed transaction scheduling. These are provided by open-source projects (such as commons logging for all log output, or commons DBCP for data connection pools), or by your application server. For the same reason, we have not provided the O/R Mapping layer. For this reason, there are good solutions such as Hibernate and JDO.
Spring aims to make existing technologies easier to use. For example, although we do not have the underlying transaction coordination processing, we provide an abstraction layer covering JTA or any other transaction policies.
Spring does not directly compete with other open-source projects unless we feel that we can provide new things. For example, many developers have never been happy with Struts and feel that there is still room for improvement in the MVC Web framework. In some fields, such as lightweight IOC containers and AOP frameworks, spring has direct competition, but there are no more popular solutions in these fields. (Spring is a pioneer in these areas .)
Spring also benefits from internal consistency.
All developers are singing the same song, and the basic idea is still the ones designed and developed by expert one-on-one J2EE.
In addition, we have been able to use some major concepts, such as inverted control, to deal with multiple fields.
Spring can be transplanted between application servers.
Of course, ensuring portability is always a challenge, but we avoid any specific platform or non-standardization and support users on WebLogic, tomcat, resin, JBoss, websphere, and other application servers.
The core of spring is an IOC/di container. It can help programmers inject dependencies between components to minimize dependencies between components and improve component reusability, spring is a low-invasive (invasive) framework, and components in spring do not realize that they are in spring, which allows components to be easily detached from the framework, components can be added to the framework in a simple way, making integration of components and even frameworks easy.
On the other hand, spring is most important to support AOP (Aspect-Oriented Programming). However, the AOP framework is only a sub-framework supported by spring, spring framework is not an appropriate description of the AOP framework. People map the novelty of AOP to spring, so that people focus on spring, although misunderstood, it also highlights another interesting feature of spring.
Spring also provides the MVC Web framework solution, but you can also combine the MVC Web framework you are familiar with spring, such as Struts and webwork, can be integrated with spring to become your own solution. Spring also provides integration in other aspects, such as the integration of persistent layers, such as JDBC, O/R Mapping tools (hibernate, ibatis), and transaction processing, spring is an all-round application framework.
Ajax
Ajax Introduction
Ajax, short for "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML), is a web page development technology used to create interactive web applications. It organically includes the following technologies: Representation of XHTML + CSS based on standards-based presentation; Dynamic Display and Interaction Using dom (Document Object Model; use XML and XSLT for data exchange and related operations; Use XMLHttpRequest for asynchronous data query and retrieval; use JavaScript to bind everything together.
Similar to DHTML or lamp, Ajax does not refer to a single technology, but organically utilizes a series of related technologies. In fact, some Ajax-based "derived/synthesized" (derivative/composite) technologies are emerging, such as "aflax ".
Ajax advantages
Traditional Web applications allow users to enter forms and send a request to the Web server when a form is submitted. The server receives and processes the form and then returns a new webpage. This method wastes a lot of bandwidth, because most of the HTML code on the first and second pages is usually the same. Because each application interaction requires sending a request to the server, the response time of the application depends on the response time of the server. This causes the user interface to respond much slower than the local application. In contrast, an Ajax application can only send and retrieve necessary data to the server. It uses soap or some other XML-based Web service interfaces and uses JavaScript on the client to process responses from the server. Because the amount of data exchanged between the server and the browser is greatly reduced, we can see applications with faster response. At the same time, a lot of processing work can be done on the client machine that sends the request, so the processing time of the Web server is also reduced.
Hibernate
Hibernate is an open-source object relationship ing framework that encapsulates lightweight JDBC objects so that Java programmers can use the object programming thinking to manipulate the database. Hibernate can replace CMP in the J2EE architecture of the application EJB to achieve data persistence. It can also be used in any scenario where JDBC is used, either in Java client or in Servlet/JSP web applications.
How hibernate works
Hibernate does not impede you or force you to modify the behavior of objects. They do not need to implement any incredible interfaces to survive. The only thing that needs to be done is to create an XML "ing document" That tells hibernate that you want to save classes in the database and how they are associated with tables and columns in the database, then it can be required to obtain data in the form of an object, or save the object as data. Compared with other solutions, it is almost perfect.
Since this article is only an introductory article, we will not introduce a specific example of building and using the hibernate ing document (in hibernate: an example is provided in the first chapters of a developer's notebook ). In addition, you can find some good examples in the online and hibernate documents. For more information, see the "Other Information" section below. It is actually quite intuitive. Attributes in an application object are associated with the correct database structure in a simple and natural way.
During runtime, Hibernate reads the ing document and dynamically constructs Java classes to manage the conversion between the database and Java. In hibernate, there is a simple and intuitive API used to query the Objects represented by the database. To modify these objects, you only need to interact with them in the program, and then tell hibernate to save the modification. Similarly, it is easy to create new objects. You only need to create them in the conventional way and then tell hibernate about them so that they can be saved in the database.
The Hibernate API is easy to learn, and its interaction with the Program Stream is quite natural. You can call it at an appropriate location to achieve your goal. It brings a lot of advantages in automation and code saving, so it is worthwhile to spend a little time learning it. In addition, you can also obtain another benefit, that is, the Code does not need to care about the type of database to be used (otherwise, you must even know ). My company has had the experience of being forced to change the database vendor in the later stages of the development process. This will cause a huge disaster. However, with hibernate, you only need to modify the hibernate configuration file.
The discussion here assumes that you have created a relational database by creating the hibernate ing document and have the Java class to be mapped. There is a hibernate "toolset" that can be used during compilation to support different workflows. For example, if you already have a Java class and ing document, Hibernate can create (or update) required database tables for you. Alternatively, Hibernate can also generate data classes only starting from the ing document. Alternatively, you can design your database and classes in reverse order to develop a ing document. There are also Alpha plug-ins for Eclipse, which can provide intelligent editing support in IDE and graphic access to these tools.
If you are using the hibernate 2 environment, these tools are rarely provided, but there are available third-party tools.
Use hibernate
Since hibernate looks so flexible and easy to use, why other tools? The following are some scenarios that can help you make judgments (perhaps by providing some comparisons and context, you can help identify scenarios that are very suitable for hibernate ).
If the application needs data storage very easily-for example, you only want to manage a group of users first-you do not need a database, not to mention a good object-link ing System (even if it is as easy to use as Hibernate )! Since Java 1.4, a standard Java Preferences API can play this role well. (You can find more information about the preferences API in the onjava article .)
For those who are familiar with relational databases and know how to execute perfect SQL queries to interact with enterprise databases, Hibernate seems to be a little out of the way, this is just like a speedboat with power and automatic gear will make performance-oriented racing drivers impatient. If you belong to this type of person, if your project team has a strong dBA, or you have some stored procedures to handle, you may want to study ibatis. The creator of hibernate regards ibatis as another interesting choice. I am very interested in it, because we once developed a similar system for an e-commerce site (with more powerful functions), and since then, we have already used it in other environments, although we prefer hibernate in new projects after we discover hibernate. You can think that the SQL-centered solution (such as ibatis) is a "reverse" Object/link ing tool, while Hibernate is a more traditional Orm.
Of course, there are other external reasons that may lead to another method. For example, in an enterprise environment, you must use a mature EJB architecture (or some other non-Common Object ing systems ). You can customize code for platforms that provide your own data storage tools, such as Mac OS X's core data. A storage specification such as an xml dtd does not involve relational databases at all.
However, if you are using a rich object model and want to save it flexibly, easily, and efficiently (whether or not you are about to start or have decided to use relational databases, as long as this is an option-and there are excellent free databases available, such as MySQL, or HSQLDB that can be embedded in Java, it should always be an option ), hibernate is probably your ideal choice. You may be surprised to save much time and enjoy it.