Struts is a Sun J2EE platform-based MVC framework, mainly the use of Servlet and JSP technology to achieve.
Struts framework can be divided into the following four main parts, three of the MVC pattern and is closely related to:
1, model (Model), essentially Model in Struts in Action is a category (this will be discussed in detail later), through the realization of the development of business logic, at the same time the user requests through the Controller (Controller) to the forwarding process of Action Based on struts-config.xml file from the description of the configuration information.
2, the view (View), View from the Controller Servlet to work with a set of JSP custom tag library consists of the use of them we can quickly build applications interface.
3, Controller (Controller), is essentially a Servlet, client requests will be forwarded to the appropriate category Action.
4, a pile of XML documents used as analytical tool kit, Struts is how to use XML to describe a number of automatically generated JavaBean properties, in addition to Struts using XML to describe the application of the international users of the message (this way applications on a multi-language support).
Spring
Spring is a lightweight application framework for J2EE.
The core of Spring is a lightweight container (container), the realization of the IoC (Inversion of Control) container model, Spring's goal is to achieve a comprehensive integration framework, the Spring framework to achieve a combination of multiple sub-frames, these sub-frames independent between each other, you can also use the framework of other alternative programs, Spring would like one-stop shop to provide a framework for the integration program.
Spring will not be putting forward some particular sub-frames to OpenSource framework with the existing competition, unless it finds the proposed new framework for enough good enough, for example, Spring's MVC framework has its own program, because it believes that the existing programs, many of the MVC can improvement, but it does not force you to use it to provide the program, you can choose the framework you want to replace the framework of his son, for example, you can still be integrated in the Spring in your Struts framework.
Spring is the core concept of IoC, IoC abstraction is "the transfer of dependency", such as "high-level modules should not rely on low-level modules, but the modules have to be dependent on the abstract" is a manifestation of IoC " must depend on the realization of the abstract, rather than rely on the realization of the abstract "is also a manifestation of IoC," the application should not be dependent on the container, but the service application container "is also a manifestation of IoC.
Spring framework of the benefits of
Spring can effectively organize your middle-tier objects, regardless of whether you choose to use the EJB. If you only Struts or other use of the APIs included in the J2EE-specific framework, you will find Spring concerned about the remaining issues.
. Spring can eliminate a number of projects in the excessive use of the Singleton. In my experience, this is a major problem, it reduces the system testability and object-oriented features.
Spring can eliminate the use of custom attributes of a wide range file format requirements, and engineering the entire application can be through a consistent approach to configuration. Who are confused to find a specific type of magic properties as a keyword or System Properties, Javadoc and even had to read the source code it? With Spring, you can be very simple to see that type of JavaBean properties. The use of inverted control (discussed below) to help complete this simplification. Spring-type rather than through the interface to promote good programming practice to reduce the cost to almost zero programming.
. Spring is designed to allow applications to use it as much as possible to create less dependence on his APIs. Spring applications in the majority of business objects is not dependent on Spring.
. The use of Spring applications easy to build unit tests.
. Spring will enable the use of EJB as a realization of choice rather than an inevitable choice for the application of the framework. You can choose to use local EJBs or POJOs to achieve business interface, but will not affect the calling code.
. Spring help you solve many problems without the use of EJB. Spring can provide a replacement of EJB objects, which for many web applications. For example, Spring can use AOP to provide a statement of affairs rather than through the use of EJB container, if you only need to deal with a single database, do not even need to achieve JTA.
. Spring for the data access framework provides a consistent, whether using JDBC or O / R mapping products (such as Hibernate).
Spring can really make you the most simple and practical solution to solve your problem. These characteristics are of great value.
Spring can do?
Spring provides many features, I will be quickly followed by all the main aspects of its display.
Task Description:
First, let us clear the scope of Spring. Although covering many aspects of Spring, but we have a clear concept of what it should be involved and what should not be involved.
Spring's main aim is to make J2EE programming easy to use and promote good habits.
Spring does not re-development of existing things. Therefore, in Spring you will find there is no logging of the package, there is no connection pool, there is no distributed transaction scheduling. These are open source projects (such as Commons Logging is used in making all of the log output, or Commons DBCP connection pool used for data), or by your application server to provide. Because the same reasons, we do not provide O / R mapping layer, which has been a good solution, such as Hibernate and JDO.
Spring's goal is to make existing technology more user-friendly. For example, although we do not have to deal with the underlying services, but we provide an abstraction layer covering the JTA or any other business strategy.
Spring and there is no direct competition to other open source projects, unless we feel we can provide something new. For example, like many developers, we have never been pleased for the Struts and the MVC web framework is there room for improvement. In some areas, such as lightweight IoC container and AOP framework, Spring has a direct competition, but in these fields have not been more popular solutions. (Spring is a pioneer in these regions.)
Spring has also benefited from the internal consistency.
All the developers are singing the same songs, the idea is still the basis of Expert One-on-One J2EE Design and Development of those.
And we have been able to use some of the key concepts, such as the inversion of control, to deal with several fields.
Spring is in the application server can be transplanted.
Ensure the portability of course, is always a challenge, but we avoid any specific platform or non-standardized, and supported in WebLogic, Tomcat, Resin, JBoss, WebSphere application server and other users.
That is the core of Spring is a IoC / DI container, it can help programmers to rely on the completion of the relationship between the components into which the dependence between the components to a minimum, thus improving reusability of components, Spring is a low-invasive (invasive) framework, Spring's components will not realize that it is actually included in the Spring, which makes components can be easily out from the framework, and almost without any changes, in turn, said that the components can also be The easiest way to add to the framework, the framework allows the integration of components even easier.
Spring on the other hand, the most important is to support AOP (Aspect-Oriented Programming), however, to support the AOP framework is only a subset of Spring framework, Spring framework is that the AOP framework is not an appropriate description, there is concern about the new mapping of the AOP to Spring, making people focus on the concerns of Spring's AOP framework on it, although a misunderstanding, but the move also highlights another concern Spring features.
Spring also provides a framework for MVC Web solution, but you can also familiar with their MVC Web Framework and Spring combined solution, such as Struts, Webwork, etc., can become integrated with the Spring into for their own solutions. Spring also provides the integration of other aspects, such as the persistence layer of integration, such as JDBC, O / R Mapping tool (Hibernate, iBATIS), transaction processing, etc., Spring made the integration of many efforts, so that the Spring is a full range of Application Framework.
AJAX
About ajax
AJAX name "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML), refers to a web-based applications to create interactive web development technologies. It contains organically following technologies: web-based standards (standards-based presentation) XHTML + CSS of that; the use of DOM (Document Object Model) for dynamic display and interaction; the use of XML and XSLT for data interchange and related operations; the use of XMLHttpRequest for asynchronous data query, retrieval; the use of JavaScript to bind everything together.
Similar to DHTML or LAMP, AJAX was not referring to a single technology, but rather a series of organic use of related technologies. In fact, some of the AJAX-based "derivative / synthetic" type (derivative / composite) technologies are emerging, such as "AFLAX".
ajax advantage
Traditional web applications allow users to fill out the form (form), when submitting a form on the web server to send a request. From the server to receive and process the form, and then return to a new page. This is a waste of a lot of bandwidth, because the two most of the HTML page code is often the same. As a result of the interaction of each application needs to send a request to the server, application response time depends on server response time. This has resulted in response to the user interface much slower than the local application. Different, AJAX applications can only send to the server and retrieve the necessary data, it uses SOAP or other XML-based web service interface, and the use of JavaScript on the client to deal with the response from the server. Because in the server and browser exchange of data between a significant reduction, resulting in faster we will be able to see the response to the application. At the same time, a lot of processing a request in the client machine, and therefore the processing time for Web servers are down.
Hibernate
Hibernate is an open source object-relational mapping framework, it had a lightweight JDBC object package so that Java programmers can use to manipulate the thinking of the object database programming. Hibernate to EJB in the application of the J2EE architecture to replace the CMP, to complete data persistence. It also can be applied to any use of JDBC occasion, either in the Java client program of practical as well as in the Servlet / JSP in Web applications
Hibernate work
Hibernate will not hinder you, it will not force you to modify the behavior of objects. They do not need to meet any of the interface incredible to be able to persist. Only need to do is create an XML "document map" to tell Hibernate that you want to save the category in the database, and how they relate to the database tables and columns, and then you can request it to the form of access to data object , or to save it as a data object. Compared with other solutions, it is almost perfect.
This article only as a result of an introductory article, it will not be introduced to build and use of Hibernate mapping document specific examples (I am in the "Hibernate: A Developer's Notebook" a book the first few chapters have been introduced in an example). In addition, the Internet and the online documentation in Hibernate, you can find some good examples, see the following "other information" section. It is actually quite intuitive. Application object attributes to a simple and natural way with the right associated with the database structure.
Runtime, Hibernate mapping files to read, and then dynamically build a Java class to manage the database and the conversion between Java. In Hibernate, there is a simple and intuitive API, for database query, said the implementation of the object. To modify these objects, (generally) only in the process of interaction with them, and then tell Hibernate to save your changes. Similarly, to create a new object is also very simple; just create them in conventional ways, and then tell Hibernate about their information, this can save them in the database.
Hibernate API is very simple to learn together, and it's interaction with the program flow very naturally. Call in the appropriate position it can reach the purpose. It brings a lot of automation and code-saving benefits, so spend some time learning it is worth it. But also get another benefit, that is not concerned about the code of the database type to use (or otherwise need to know). My company has had in the development process of the latter was forced to replace the experience of the database vendors. This will cause a huge disaster, but through the use of Hibernate, simply Hibernate configuration file can be modified.
Discussed here assume that you have through the creation of Hibernate mapping files, set up a relational database and have to map the Java type. A Hibernate "tools" can be used at compile time to support the different workflows. For example, if you already have Java classes and mapping files, Hibernate can you create (or update) the necessary database tables. Or, just to start from the mapping document, Hibernate can generate data type. Alternatively, it can reverse-engineer your database and type in order to document the development of mapping. Some of the alpha for the Eclipse plug-in, they can be provided in the IDE to support intelligent editing, as well as graphical access to these tools.
If you are using Hibernate 2 environment, these tools provide little, but the existence of third-party tools available.
Occasions the use of Hibernate
Since such a flexible and easy to use Hibernate looks, why does the use of other tools? There are a number of scenes that can help you to determine (perhaps by providing a number of comparison and context, can help to identify Hibernate is ideal for the occasion).
If the application needs for data storage is very simple - for example, you want to manage a group of user preference - you do not need a database, not to mention an excellent object - relational mapping system has been (even if it so as Hibernate easy-to-use)! Java 1.4 from the beginning, there is a standard Java Preferences API is well positioned to play that role. (In ONJava article can be found on the Preferences API for more information.)
For those familiar with the use of relational database and learn how to perfect the implementation of enterprise database SQL query and the people who interact, Hibernate seems cumbersome, it is like a dynamic and automatic downshift vehicle speed of the car will focus on performance, as impatient drivers . If you belong to such people, if your project team have a strong DBA, or have some stored procedures to deal with, you may want to look at iBATIS. The founder of Hibernate itself, as they iBATIS is another interesting choice. I am very interested in it because we have an e-commerce site developed a similar system (and its function is more powerful), and then to the present, we have used in other environments, despite the discovery of Hibernate After the new project, we usually prefer to use Hibernate. You can view, SQL-centric solutions (such as iBATIS) is the "reverse of the" object / relational mapping tool Hibernate is a more traditional ORM.
Of course, there are other external factors will lead to the use of other methods. For example, in an enterprise environment, you must use the maturity structure of the EJB (or some other non-ordinary object mapping system). Can provide their own tools for data storage platform tailored code, such as Mac OS X's Core Data. May be used such as XML DTD storage specification, and it does not involve relational database.
However, if you are using a rich object model, and want a flexible, easy and efficient to keep it (whether or not you are about to start or have already decided to use relational database, as long as it is a choice - and there is an excellent free database available , such as MySQL, or Java-embedded HSQLDB, it should always be an option), then Hibernate is very likely that your ideal choice. You may be surprised at the number of time-saving, as well as how you will like to use it.







