Experience 9--jsp Design Template __js

Source: Internet
Author: User

1. There are 4 kinds of common object-oriented design patterns:

Factory mode, singleton mode, facade mode, and MVC architecture pattern.

After Sun introduced JSP technology, it also recommended two kinds of Web application development mode, one is Jsp+javabean mode, one is Servlet+jsp+javabean (MVC) mode.

The JSP design pattern includes two:

(1) Model1,jsp+javabean design mode

(2) MODEL2,MVC design mode

mode one Jsp+javabean mode:

In this mode, the JSP page responds to the request alone and returns the processing results to the customer, and all database operations are implemented through JavaBean. using this pattern in large numbers often leads to embedding a large amount of Java code in a JSP page, which can become a bad thing when the business logic that needs to be handled is very complex . A lot of Java code makes JSP pages very bloated. A slight carelessness on the front page designers can break code that is related to business logic. This situation often occurs in large projects, creating difficulties in code development and maintenance, and can lead to project management difficulties. So this model only applies to small and medium scale projects. The Jsp+javabean model is suitable for developing Web applications with less complex business logic, in which JavaBean is used to encapsulate business data, and JSP is responsible for processing user requests and displaying data.

Pattern two MVC pattern:

" MVC" mode is: "Model-view-controller" mode . In this mode, through the JSP technology to represent the page, through the servlet technology to complete a large number of transaction processing, to achieve the user's business logic. In this mode, the servlet is used to handle the requested transaction, acting as the role of the controller (Controller, "C"), which responds to customer requests for business logic and decides which JSP page to send to the customer based on the user's request behavior. The JSP page is in the presentation layer, which is the role of the view (view, "V"). JavaBean is responsible for the processing of the data, which is the role of the model ("M").

The Servlet+jsp+javabean (MVC) model is suitable for the development of complex Web applications in which the Servlet handles user requests, JSP is responsible for data display, and JavaBean is responsible for encapsulating the data. servlet+jsp, JavaBean mode program each module between the level of clear, Web development recommended the use of this model.

2. MVC Architecture

The Model-view-controller architecture pattern was invented in the Smalltalk-80 GUI (a classic object-oriented programming language) laboratory in the 80 's. According to the MVC pattern, a software should separate the business logic (model) from the display (view). Separation has many advantages, the most important of which are two aspects :

1, the same business logic layer (Model) may correspond to multiple display layer (View), if the business logic layer and display layer together, then add a display layer will greatly increase the complexity of the component. An example of a business logic to two display layers is: The business logic layer of the bank's account corresponds to the ATM and Internet two display layers.

2, usually, every time you modify the display layer does not need to modify the business logic layer.

the MVC model based on the bean:

The bean can be implemented using JavaBean, or EJB (Enterprise-Class JavaBean, here is not much to do introduction, attention will be introduced later) to achieve, respectively, the system is composed of:

n JavaBean (M) +jsp (V) +servlet

The n EJB (M) +jsp (V) +servlet (C) is implemented.

the MVC model based on struts:

Struts is a project of the Apache organization, like other Apache projects, it is also an open source project. Struts is a better MVC framework that provides low-level support for developing MVC systems, with the main technology being the servlet,jsp and custom tag library. The main point here is that the struts framework is developed based on the MVC design pattern.

Struts is a set of mutually collaborative classes, Servlet, and JSP tags that form a reusable MVC design . This definition indicates that struts is a framework, not a library, but struts also contains a rich tag library and utility classes that work independently of the framework. The basic structure of struts is shown in the figure.

Related Article

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.