Summary of SSH framework in java

Struts

  1. Struts is a Web layer framework designed according to the MVC pattern. In fact, it is a large servlet. The servlet is called ActionServlet, or a subclass of ActionServlet. We can hand over all requests that meet certain characteristics to this servlet in the web.xml file, and the servlet then refers to a configuration file (usually /WEB-INF/struts-config.xml) to assign each request to different action to process.
    An extended knowledge point: struts can have multiple configuration files, and their configuration files can be configured according to modules, which can prevent excessive expansion of configuration files;
  2. ActionServlet encapsulates the request parameters into a formbean object (that is, a java class, each attribute in this class corresponds to a request parameter) before handing the request to action for processing, and what kind of formbean object is encapsulated into? See configuration file.
    3. It should be noted that before the ActionServlet passes the formbean object to the execute method of the action, it may call the validate method of the formbean for verification. Only after the verification is passed, the formbean object is passed to the execute method of the action. Otherwise, it An error page will be returned. This error page is specified by the input attribute. (See the configuration file). Why did the author name it as the input attribute instead of the error attribute? We will analyze it later in combination with the actual operation effect.
    4. After the action is executed, the displayed result view should be returned. This result view is represented by an ActionForward object. The actionforward object is associated with a jsp page through the configuration in the struts-config.xml configuration file, because the program uses It is the logical name set for the jsp page in the struts-config.xml configuration file, which can realize the decoupling of the action program code and the returned jsp page name.

Hibernate

  1. The internal operation process of object-oriented design software can be understood as the continuous creation of various new objects, the establishment of relationships between objects, and the invocation of object methods to change the state of each object and the process of object demise, regardless of the process and operation of the program. No matter what, it is essentially to get a result, and the difference between the running result of the program at the previous moment and the next moment is reflected in the change of the object state in the memory.
    2. In order to maintain the running state of the program in the case of shutdown and insufficient memory space, it is necessary to save the state of the object in the memory to the persistent device and restore the state of the object from the persistent device, usually in a relational database. to store a large amount of object information. In terms of the running function of Java programs, the function of saving object state should be a very inconspicuous auxiliary function compared with other functions of system operation. Java uses jdbc to realize this function, but this inconspicuous function has to be written A lot of code, and the only thing to do is to save objects and restore objects, and those large amounts of jdbc code have no technical content. They are basically written using a set of routine standard code templates, which is a kind of hard work and repetition. Work.
    3. Saving the objects generated when the java program is running and restoring the objects through the database actually realizes the mapping relationship between java objects and relational database records, which is called ORM (ie Object Relation Mapping). People can achieve this by encapsulating JDBC code. The packaged products are called ORM frameworks, and Hibernate is one of the popular ORM frameworks. Using the Hibernate framework, you don't need to write JDBC code, just call a save method, you can save an object to the relational database, and just call a get method, you can load an object from the database.
    4. The basic process of using Hibernate is: configure the Configuration object, generate the SessionFactory, create the session object, start the transaction, complete the CRUD operation, submit the transaction, and close the session.
    5. When using Hibernate, you must first configure the hibernate.cfg.xml file, which configures database connection information and dialects, etc., and configures the corresponding hbm.xml file for each entity. Each entity needs to be registered in the hibernate.cfg.xml file. hbm.xml file.
    6. When applying Hibernate, it is important to understand the caching principle of Session, cascade, lazy loading and hql query.
    3. The role of AOP.
    Spring

1. Spring implements the factory class of the factory pattern (it is necessary to explain what the factory pattern is here), this class is named BeanFactory (actually an interface), and is usually a subclass of ApplicationContext of BeanFactory in the program. Spring is equivalent to a large factory class. In its configuration file, the class name used to create the instance object and the properties of the instance object are configured through elements.
2. Spring provides good support for IOC. IOC is a programming idea and an architectural art. Using this idea, the decoupling between modules can be well realized. IOC is also called DI (Depency Injection). What is dependency injection?
For example, Class Programmer
{
Computer computer = null;
public void code()
{
//Computer computer = new IBMComputer();
//Computer computer = beanfacotry.getComputer();
computer.write();
}
public void setComputer(Computer computer )
{
this.computer = computer;
}
}
The other two ways are dependent on the first one directly depends on the target class, the second one transfers the dependency to the factory, and the third one is completely decoupled from the target and the factory. The configuration fragment in spring's configuration file is as follows:




3. Spring provides a good encapsulation of AOP technology. AOP is called aspect-oriented programming, which means that there are many methods of unrelated classes in the system. In these many methods, some system function code should be added, for example, adding logs , adding permission judgment, adding exception handling, this application is called AOP. The proxy technology is used to realize the AOP function. The client program no longer calls the target, but calls the proxy class. The proxy class and the target class have the same method declaration to the outside world. There are two ways to achieve the same method declaration. One is to achieve the same method declaration. The second is the subclass of the target. In the JDK, the Proxy class is used to generate a dynamic proxy to generate an implementation class for an interface. If you want to generate a subclass for a class, you can use CGLI B. Add the system function and call the corresponding method of the target class to the method of the generated proxy class. The proxy of the system function is provided by the Advice object. Obviously, to create the proxy object, at least the target class and the Advice class are required. Spring provides this support, and you only need to configure these two elements in the spring configuration file to implement proxy and aop functions, for example,



Advantages and disadvantages of Struts
Advantages :
1. Implement the MVC pattern, with a clear structure, so that developers only focus on the realization of business logic.
2. There are abundant tags available, Struts tag library (Taglib), if it can be used flexibly, it can greatly improve the development efficiency
. 3. Page Navigation
Make the context of the system clearer. Through a configuration file, you can grasp the relationship between the various parts of the entire system, which is of great benefit for later maintenance. Especially when another group of developers took over the project, this advantage became more obvious.
4. Provide Exception handling mechanism.
5. Database link pool management
6. Support I18N
Disadvantages
1. When transferring to the display layer, you need to configure forward. If there are ten jsp of the display layer, you need to configure ten struts, and it does not include the When the directory and file are changed, the forward needs to be re-modified. Note that after each modification of the configuration, the entire project is required to be redeployed, and a server such as tomcate must be restarted.
Second , the Action of Struts must be thread-safe, which only Allows one instance to handle all requests. Therefore, all the resources used by the action must be synchronized uniformly, which causes the problem of thread safety.
Third, the test is inconvenient. Each Action of Struts is coupled with the Web layer, so that its testing depends on the Web container, and unit testing is also difficult to implement. However, there is a Junit extension tool, Struts TestCase, that can implement its unit testing.
4. Type conversion. Struts FormBean treats all data as String type, and it can use the tool Commons-Beanutils for type conversion. But its transformations are all at the Class level, and the type of transformation is not configurable. It is also very difficult to return an error message during type conversion to the user.
Fifth, the dependence on Servlet is too strong. Struts must rely on ServletRequest and ServletResponse when dealing with Action, so it cannot get rid of Servlet container.
6. Front-end expression language. Struts integrates JSTL, so it mainly uses JSTL's expression language to obtain data. But JSTL's expression language is weak in handling collections and indexed properties.
Seven, it is difficult to control the execution of Action. Struts creates an Action, if you want to control its execution order, it will be very difficult. Even you have to re-write Servlet to achieve your functional requirements.
Eight, before and after the Action is processed. When Struts handles the Action, it is based on the hierarchy of the class, and it is difficult to operate before and after the Action is processed.
Nine, the event support is not enough. In struts, a form Form corresponds to an Action class (or DispatchAction), in other words: in Struts, a form can only correspond to one event, and the event method of struts is called application Event, application event and component event are a coarse-grained event.
1. Spring
Spring is a powerful framework that solves many common problems in J2EE development. Spring provides a consistent approach to managing business objects and encourages the injection of good habits of programming to interfaces rather than classes. Spring's architectural foundation is based on the Inversion of Control container using JavaBean properties. However, this is only part of the complete picture: Spring is unique in using the IoC container as a complete solution that focuses on all architectural layers. Spring provides the only data access abstraction, including a simple and efficient JDBC framework, which greatly improves efficiency and reduces possible errors. Spring's data access architecture also integrates with Hibernate and other O/R mapping solutions. Spring also provides the only transaction management abstraction that provides a consistent programming model across various underlying transaction management technologies such as JTA or JDBC transactions. Spring provides an AOP framework written in standard Java that provides declarative transaction management and other enterprise transactions for POJOs - if you need them - and also implement your own aspects. This framework is powerful enough to allow applications to throw away the complexities of EJBs while enjoying the key services associated with traditional EJBs. Spring also provides a powerful and flexible MVC web framework that can be integrated with the IoC container.

Second, STRUCTS
Struts is an MVC framework based on the Sun J2EE platform, mainly using Servlet and JSP technology to achieve. Since Struts can fully meet the needs of application development, it is easy to use, agile and fast, and it has attracted much attention in the past year. Struts integrates Servlet, JSP, custom tags and message resources into a unified framework. When developers use it for development, they do not need to code and implement a full set of MVC patterns, which greatly saves time. Therefore, Struts Is a very good application framework.

3. Hibernate
Hibernate is an open-source object-relational mapping framework. It encapsulates JDBC with a very lightweight object, so that Java programmers can use object programming thinking to manipulate the database at will. Hibernate can be used in any occasion using JDBC, it can be used in Java client programs, and can also be used in Servlet/JSP Web applications. The most revolutionary thing is that Hibernate can replace CMP in the J2EE architecture that uses EJB. , to complete the task of data persistence. , Hibernate can replace CMP in the J2EE architecture of the application EJB, complete the heavy task of data persistence.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325860866&siteId=291194637