Struts
Struts is an MVC framework based on the Sun EE platform, which is implemented mainly by servlet and JSP technology.
The struts framework can be divided into the following four main sections, three of which are closely related to the MVC pattern:
1, model, essentially in struts, the model is an action class (this will be discussed in detail later), through which the developer implements the business logic, while the user requests through the controller The forwarding process to the action is based on the configuration information described by the Struts-config.xml file.
2. Views, view, is composed of a set of JSP custom tag libraries that work with the controller servlet, which allows us to quickly build the interface of the application system.
3, controller, is essentially a servlet that forwards the client request to the appropriate action class.
4. A bunch of toolkits for XML file parsing, struts uses XML to describe how to automatically generate some JavaBean properties, and struts uses XML to describe user-prompted information in internationalized applications (which enables multi-language support of the application system).
Spring
Spring is a lightweight Java EE application framework.
The core of spring is a lightweight container (container) that implements the IOC (inversion of Control) mode container, and the goal of spring is to implement a full-fledged integration framework that implements a combination of multiple sub-frameworks in the spring framework, These sub-frameworks can be independent of each other, or can be replaced with other framework schemes, and Spring wants to provide a framework consolidation solution for One-stop shop.
Spring does not particularly propose sub-frameworks to compete with the existing opensource framework, unless it feels that the proposed framework is new enough, such as spring has its own MVC framework scheme, because it feels that there are many improvements to the existing MVC scheme, But it does not force you to use the scenario it provides, and you can choose the framework you want to replace its sub-framework, such as you can still integrate your struts framework in spring.
Spring's core concept is that IOC,IOC's abstract concept is "transfer of dependencies", such as "high-level modules should not rely on the lower modules, but the module must rely on abstraction" is a manifestation of the IOC, "implementation must rely on abstraction, rather than abstract dependency implementation" is also a manifestation of the IOC, " Applications should not be dependent on containers, but containers serving applications "is also a manifestation of the IOC.
The architectural benefits of spring
Spring effectively organizes your middle-tier objects, whether or not you choose to use EJBS. If you just use struts or other frameworks that contain the Java EE-specific APIs, you'll find that spring is focused on the legacy.
. 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 nature of the system.
Spring eliminates the need to customize files with attributes in a variety of formats, and is configured in a consistent way throughout the application and engineering. Ever confused, a particular class looking for a psychedelic attribute keyword or system attribute, do you have to read Javadoc or even source code? With spring, you can easily see the JavaBean property of the class. The use of inverted controls (discussed below) helps to accomplish this simplification. Spring can promote good programming habits through interfaces rather than classes, reducing programming costs to almost zero.
. 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.
. Applications built using spring are easy to unit test.
. Spring enables the use of EJBS to be 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.
. Spring helps you solve many problems without using EJBS. Spring provides an alternative to EJBS that are suitable for many Web applications. For example, spring can use AOP to provide declarative transactions without using an EJB container, if you only need to deal with a single database, and you don't even need a JTA implementation.
. Spring provides a consistent framework for data access, whether using JDBC or O/R mapping products such as hibernate.
Spring does enable you to solve your problem with the simplest possible solution. These features are of great value.
What can spring do?
Spring provides a number of features, where I'll quickly show each of its main areas in turn.
Task Description:
First, let's clarify the spring range. Although spring covers many aspects, we already have a clear concept of what it should involve and what should not be involved.
The main purpose of spring is to make the Java EE easy to use and promote good programming habits.
Spring does not re-develop what is already there. Therefore, in spring you will find a packet without logging, no connection pool, and no distributed transaction scheduling. These are available in open source projects (for example Commons Logging is used to do all the log output, or Commons dbcp used as a data connection pool) or provided by your application server. For the same reason, we did not provide the O/R mapping layer, there are good solutions such as Hibernate and JDO.
Spring's goal is to make existing technologies easier to use. For example, although we do not reconcile the underlying transaction, we provide an abstraction layer that overrides JTA or any other transaction policy.
Spring does not compete directly with other open source projects unless we feel that we can offer something new. For example, like many developers, we have never been happy with struts and feel that there is room for improvement in the MVC Web framework. In some areas, such as the lightweight IOC container and the AOP framework, Spring has direct competition, but there are no already popular solutions in these areas. (Spring is a pioneer in these areas.) )
Spring also benefits from intrinsic consistency.
All the developers are singing the same hymn, the basic idea is still the expert one-on-one EE design and development of those.
And we have been able to use some of the main concepts, such as inverted control, to handle multiple areas.
Spring is portable between application servers.
Of course, portability is always a challenge, but we avoid any particular platform or non-standardization, and support users on Weblogic,tomcat,resin,jboss,websphere and other application servers.
The core of spring is a Ioc/di container that helps program designers complete dependency injection between components, minimizing dependencies between components, and increasing reuse of components, and spring is a low-intrusive (invasive) framework. The components in spring do not realize that it is in spring, which allows components to be easily detached from the framework without any modification, and conversely, components can be added to the framework in a simple way, making it easy to integrate components and even frameworks.
Spring's most important aspect is support for AOP (aspect-oriented programming), but the AOP framework is just a sub-framework that spring supports, saying that the spring framework is an AOP framework that is not an appropriate description, and that people are The emphasis on the AOP focus on spring, which focuses on its AOP framework, is somewhat misleading, but it also highlights another interesting feature of spring.
Spring also provides solutions to the MVC Web framework, but you can also integrate your familiar MVC Web framework with spring, such as struts, webwork, and so on, all of which can be integrated with spring into your own solution. Spring also provides other aspects of integration, such as the integration of persistent layers such as JDBC, O/R mapping Tools (Hibernate, IBATIS), transaction processing, and so on, and spring is a full-fledged application framework for the multi-faceted integration effort.
AJAX
Introduction to Ajax
The Ajax full name "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML) refers to a web development technique that creates an interactive Web application. It organically contains the following technologies: Web-based standard (standards-based presentation) XHTML+CSS representation, dynamic display and interaction using the DOM (Document Object Model), and XML and XSLT Data exchange and related operations; Use XMLHttpRequest to query and retrieve asynchronous data; Use JavaScript to bind everything together.
Similar to DHTML or Lamp,ajax does not refer to a single technique, but rather organically utilizes a range of related technologies. In fact, some Ajax-based "derivation/composition" (derivative/composite) technologies are emerging, such as "Aflax".
Ajax advantages
Traditional web apps allow users to fill out forms (form) and send a request to the Web server when the form is submitted. The server receives and processes the incoming form, and then returns a new page. This approach wastes a lot of bandwidth, because most of the HTML code in the front and back two pages is often the same. Because each application interaction requires 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 more slowly than the local application. Unlike this, an AJAX application can send and retrieve only the necessary data to the server, using SOAP or some other XML-based Web service interface, and using JavaScript on the client to process the response from the server. Because the amount of data exchanged between the server and the browser is much reduced, the result is that we can see applications that respond faster. At the same time, a lot of processing can be done on the client machine making the request, so the processing time of the Web server is also reduced.
Hibernate
Hibernate is an open-source object-relational mapping framework that provides a lightweight object encapsulation of JDBC, allowing Java programmers to manipulate databases using object-programming thinking. Hibernate can be used to replace CMP in the Java EE architecture of the EJB application to complete data persistence. It can also be applied to any application using JDBC, either in Java client applications or in servlet/jsp Web applications
How Hibernate works
Hibernate does not interfere with you, nor does it force you to modify the way objects behave. They do not need to implement any magical interfaces to be able to persist. The only thing you need to do is create an XML "map document" that tells hibernate the classes you want to be able to save in the database, and how they relate to the tables and columns in that database, and then you can either ask it to get the data as an object, or save the object as data. It's almost perfect compared to other solutions.
Because this article is just an introductory article, there are no specific examples of building and using Hibernate mapping documents (I've covered an example in the first few chapters of Hibernate:a Developer's Notebook). In addition, some good examples can be found in online and hibernate documentation, see the " Additional information " section below. It's actually quite intuitive. The properties in the Application object are associated with the correct database structure in a simple and natural way.
At run time, hibernate reads the mapping document and then dynamically constructs the Java class to manage the transformation between the database and Java. In Hibernate, there is a simple and intuitive APIfor executing queries against 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 changes. Similarly, it's easy to create new objects by simply creating them in the usual way and then telling hibernate about them so that they can be saved in the database.
The Hibernate API is simple to learn, and its interaction with program flow is quite natural. It can be achieved by invoking it at the appropriate location. It brings a lot of automation and code savings benefits, so it's worthwhile to spend a little time learning it. There is another benefit, too, that the code doesn't care about the kind of database you want to use (or even need to know). My company has experienced the forced replacement of database vendors late in the development process. This can be a huge disaster, but with hibernate, you simply need to modify the hibernate configuration file.
The discussion here assumes that you have created a relational database by creating a Hibernate mapping document, and that you have a Java class to map. There is a hibernate "toolset" that can be used at compile time to support different workflows. For example, if you already have a Java class and a mapping document, hibernate can create (or update) the required database tables for you. Alternatively, hibernate can generate data classes just starting with the mapping document. Or, it can reverse-engineer your database and class to develop a mapping document. There are also Alpha plug-ins for Eclipse, which provide intelligent editing support and graphical access to these tools in the IDE.
If you are using the Hibernate 2 environment, these tools are rarely available, but there are third-party tools available.
Where to use Hibernate
Since hibernate looks so flexible and useful, why use other tools? Here are some scenarios that can help you make judgments (perhaps by providing some comparison and context that can help you identify situations that are very suitable for hibernate).
If the application is very simple for data storage-for example, you just want to manage a set of user preferences-you don't need a database at all, let alone a good object-relational mapping system (even if it's as easy to use as Hibernate)! Starting with Java 1.4, there is a standard Java Preferences API that can work well. (You can find more information about the preferences API in the Onjava article .) )
For those familiar with using relational databases and understanding how to perform perfect SQL queries with enterprise database interactions, hibernate seems to be in the way, just as a speedboat with power and automatic gears can make performance-conscious racing drivers impatient. If you belong to this kind of person, if your project team has a strong DBA, or there are some stored procedures to handle, you might want to study IBATIS. The creator of Hibernate itself treats Ibatis as another interesting option. I am interested in it because we have developed a similar system for an e-commerce site (which is more powerful), and since then, we have used it in other environments, although we usually prefer hibernate in new projects after we discover hibernate. You can argue that a SQL-centric solution (such as Ibatis) is a "reverse" object/Relationship mapping tool, and Hibernate is a more traditional ORM.
Of course, there are other external causes that can lead to another approach. For example, in an enterprise environment, you must use a mature EJB schema (or some other non-trivial object mapping system). You can customize the code for the platform that provides your own data storage tools, such as Mac OS X's Core data. It is possible to use a storage specification such as an XML DTD that does not involve a relational database at all.
However, if you are using a rich object model and want to save it flexibly, easily, and efficiently (whether you are starting or deciding to use a relational database, as long as this is a choice-and there are good free databases available, such as MySQL, or embedded Java HSQLDB, it should always be a choice), then hibernate is probably your ideal choice. You may be amazed at how much time is saved, and how much you will like to use it.
The application of simple Java framework