What is the SSH framework?

Source: Internet
Author: User

I believe that the shoes I read in this article are basically just getting started and I am trying to find a direction. So I will try my best to minimize the details and background knowledge, and strive to be concise and easy to understand. Of course, if the experts find any errors or errors after reading the text, please correct them.

Go to the topic. Currently, most of the web pages we visit are dynamic web pages, which are compared with static web pages that are purely HTML when the Internet was just emerging. Dynamic Web pages are those that are dynamically generated by servers on the website based on user requests. The content of static Web pages remains unchanged. The most fundamental of dynamic web page development is the process in which the server receives a request submitted by the browser and generates a complete HTML document through a series of program operations, which is then displayed by the browser.

The most primitive way to write dynamic web pages is to use servlet, which is actually to pass user requests to a Java class. This class is responsible for analyzing the content in the request and then outputting a line of HTML code with println, it is displayed in the browser. This method can indeed dynamically generate Web pages, but there are two fatal problems that cannot be solved. First of all: HTML has always been a magic weapon for web designers. They can design beautiful and beautiful pages, but when using Servlet development, they should output these documents in Java, this makes it necessary for the designer to master Java. Second, even Java developers, using println to correctly and completely output complex webpage content is not a simple task, or simply impossible.

Later, people changed their thinking, so JSP emerged, allowing Java code to be embedded into the designed HTML page. Solved the two problems encountered when using Servlet to develop dynamic pages. For web designers, what they face is still the HTML they are familiar with, but some special labels are extended to accommodate the business logic code. Java programmers can also concentrate on writing Java code related to business logic. The server automatically converts the Java code in JSP to servlet, which reduces the burden on developers to a certain extent. However, this implementation method adds the display logic and business logic of the page to the JSP page. Either the front-end page or the back-end logic must be modified by the other party, it increases maintenance costs.

Then, the most basic MVC layering is implemented using the new mode of JSP + servlet + JavaBean. This structure is called MVC model1. A JSP is displayed at the front-end, a servlet is responsible for process logic control, and a Javabean is responsible for data encapsulation. Yes, this structure still has a problem: Because the JSP page still needs to use symbols to embed a lot of Java code, which leads to chaotic page structure. servlet and JavaBean are responsible for a lot of Jump and computation work, tightly coupled, low program reusability, and so on. This caused widespread attention to the use of script elements in JSP pages, which led to the development of alternative solutions.

Jsp2.0 standard tag library jstl (JSP standard tag Library) is introduced ). This is a set of custom tag libraries that implement common functions in Web applications. These functions include iteration and condition judgment, data management formatting, XML operations, and database access. This eliminates the need for web designers to embed scripts into pages to implement basic page logic.

In MVC model 2, the servlet is incorporated into the architecture to assume the frontend controller role, and the requests sent by the web browser are sent to the servlet in a centralized manner, servlet can centrally manage user login, permission control, multi-language conversion, and other pre-processing, and then switch to the corresponding JSP processing as needed. Model 2 adopts the better MVC mode, but increases the complexity of writing.

To simplify development, Struts emerged. Therefore, the purpose is to help us reduce the time needed to develop Web applications using MVC design models. For different businesses, we need an action class for page Jump and background logic operations, and one or several JSP pages for data input and output display, another Form class is used to transmit data between action and JSP. In JSP, you can use a group of tags provided by the Struts framework, which is as simple as using HTML tags and can complete complicated logic. In struts, the business logic code is placed in the action. These codes must inevitably deal with the database, for example, reading information from the database and storing the operated information back to the database. However, it is very cumbersome to use complex SQL statements to read, write, and close the connection. The obtained data needs to be converted or encapsulated before being passed out. When the project is large to a certain extent, you need to maintain the database independently.

In this case, the Hibernate framework appears. It requires you to create a series of persistence classes. The attributes of each class can be viewed as one-to-one correspondence with the attributes of a database table, of course, relational databases can also be associated with various table parts. When we need related operations, we don't need to pay attention to database tables any more. We do not need to query the database row by row. We only need persistence classes to add, delete, modify, and query functions. Make our software development truly object-oriented, rather than confusing code. I feel that using hibernate reduces the programming workload by 80% compared with the JDBC Method.

Now we have three layers, but what is the call between each layer? For example, Struts at the display layer needs to call a business class, and a new business class is required for use. The business layer needs to call the class at the persistent layer, and a new persistent layer class is also required for use. Mutual calling through this new method is the worst embodiment of software development. Simply put, the caller dependency is called, and there is a strong coupling between them. If I want to reuse a class elsewhere, other classes that the class depends on also need to be included. The program becomes very messy. Each class is mutually dependent and called, and the reusability is extremely low. If a class is modified, many classes dependent on it will be affected. For this reason, the Spring framework appears.

Spring completely decouples the dependencies between classes. If a class depends on anything, it is an interface. It is not important to implement this interface. As long as you get a class that implements this interface, you can easily inject the implementation class into the class that calls the interface through the xml configuration file. This dependency between all classes is completely replaced by the configuration file. Therefore, the core of the Spring framework is the so-called dependency injection and control inversion.

Struts is responsible for the display layer, Hibernate is responsible for the persistence layer, and spring is responsible for the intermediate business layer. This structure is currently the most widely used Java Web application architecture.

Original article link

What is the SSH 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.