Learning model-View-controller MVC pattern

Source: Internet
Author: User

Introduction to MVC :

MVC begins in the desktop program, M refers to the business model, v refers to the user interface ,C is the controller, the purpose of using MVC is to separate m and v implementation code, so that the same program can use different representations. MVC is a pattern of creating WEB applications using MVC (Model View Controller-View-controller) Design:

Model (models) represent the core of the application (such as a list of database records).

View displays data (database records).

The controller (Director) processes the input (writes to the database record).

The MVC pattern also provides complete control over HTML, CSS, and JavaScript.

model (models) is the part of the application that handles application data logic.
Typically, model objects are responsible for accessing data in the database.

view (views) is the part of the application that handles the display of data.
Typically views are created from model data.

controller (Controllers) is the part of the application that handles user interaction.
Usually the controller is responsible for reading data from the view, controlling user input, and sending data to the model.

The main components of a Java Web application

1.Servlet components

The servlet runs in a web container, such as Tomcat, which can be dynamically loaded by the Web container, receiving browser requests, invoking other components to process requests, and then returning the processing results.

when a browser accesses a servlet, the Web container creates a ServletRequest object and a Servletresponse object, and encapsulates the user's request information in the ServletRequest object. The two objects are then transferred as parameters to the specific method of the servlet. In this method, the request is processed, the processing result is encapsulated in the Servletresponse object, and returned to the Web container. Finally, the Web container returns the results to the browser to parse and display.

2.JSP components

JSP is a Dynamic Web page technology. It adds the HTML page to the Java script, and the JSP tag forms the JSP file. When a browser requests a JSP page, Tomcat translates the JSP page into a Java file. It then compiles it into a class file, executes it, and returns the resulting HTML page to the client display.

3.JavaBean components

The JavaBean component is a Java object that conforms to a specific specification. A series of properties are defined in the JavaBean component, and each property provides a setter and getter method so that you can use the component to store some intermediate data. For example, ServletRequest request information, information from the database, and so on.

4.EJB components

Enterprise Java? The Bean (EJB) component is the Java component on the server side. This component is based on the standard distributed object technology, CORBA and RMI technologies, which are used to implement the amount of business logic for enterprise-level applications.

5.XML language

XML (extensible Markup Language) is a markup language used to create custom tags.

6.Web Server and Application server

The Web server is used to process HTTP requests and return HTTP data. It is mainly used to interact with the browser to provide services to the user. The application server can be called by the Web server to handle the business logic. The data it returns is organized into HTML format by the Web server and then returned to the browser to parse.

J Ava Web Solution (development method)



Jsp+javabean Development Mode:
Features: This mode separates the business logic from the page performance, and increases the debugging and maintainability of the program to some extent.
Cons: The page will be controlled and displayed in a set.
Conclusion: simple, suitable for the rapid construction and operation of small projects.

Jsp+servlet+javabean Development Mode:
Features: JSP as a view to the performance of the page, servlet as a controller, control program process and call the business processing; JavaBean encapsulates the business logic. Followed the MVC design pattern.
Cons: No unified development framework leads to long development cycles.

Struts Development Scenarios:
Features: A mature MVC development framework.
Composition: Controller: Actionservlet component: The central controller of the struts frame.

Requestprocessor components: Each submodule has a request processor.
Action component: A business agent that invokes the model for a specific business logic process.
Views: mainly composed of JSP pages include HTML documents, standard tag libraries (JSTL) and Struts tag libraries, JavaScript scripts and CSS styles, multimedia files, message resource files, actionform classes.
mode: usually inOther model builds are used in structs to implement business logic. such as: JavaBean technology, EJB Technology, hibernates design mode.
conclusion: For some large-scale projects,The struts framework improves development efficiency and has great benefits for later maintenance.

Spring Development Scenarios:
Features: Based on two advanced technologies of IOC and AOP, the perfect simplification of the complexity of enterprise-level development is an ideal Web program framework.
Composition: Core module: The implementation of IOC mode, including the Beanfactory class is responsible for the configuration and management of JavaBean.
Context module: inherits the Beanfactory class and adds functions such as event handling, internationalization, resource loading, transparent loading, and data validation, providing framework-style bean access and many enterprise-class features. such as: Jndi access, support EJB, remote call, inherit template framework, e-mail and scheduled task scheduling.
AOP module: Provides an AOP framework written in the standard Java language that allows applications to throw away the complexity of EJBS, but with the key functionality of traditional EJBS.
DAO Module: Provides an abstraction layer of JDBC and provides support for declarative and programmatic transactions.
Web module: Built on the context module, provides the context of the servlet listener and the contexts of the Web application.
Integrates with existing web frameworks such as: JSF, Tapestry, struts, and more.
O/R Mapping module: provides support for existing ORM frameworks such as Hibernate.
Spring MVC framework: Built on top of core modules, it adapts to multiple views, template technology, internationalization, and validation services, enabling clear separation of control logic and business logic.

Struts+hibernate Development Program:
Features: Using Struts's MVC design pattern, a development program that consists of hibernate persistence objects.

Struts+spring+hibernate Development Program:
Features: Struts is responsible for the presentation layer, spring is responsible for the logic layer of the business, Hibernate persistence layer in the database operation, composed of development scenarios.

used in The MVC framework of the Java Web

Struts is an MVC framework based on the Sun EE platform, which is implemented mainly by servlet and JSP technology. Because struts can fully meet the needs of application development, easy-to-use, agile and rapid, over the past year has been a considerable concern. Struts consolidates Servlets, JSPs, custom tags, and information resources into a single, unified framework that developers can use to develop without having to encode themselves to implement a full set of MVC patterns, greatly saving time.

Spring MVC should be the most common. The Spring Web MVC Framework (Spring MVC) is a rich Model view Control WEB framework. Using the Dispatcher servlet to publish request processing, he uses configurable handler mappings, view resolution, and theme solutions.

Hibernate is an open-source object-relational mapping framework that provides JDBC with a very lightweight object encapsulation that allows Java programmers to manipulate databases at will using object programming thinking. Hibernate can be applied to any JDBC application, both in Java client applications and in servlet/jsp Web applications, and most revolutionary is that hibernate can replace CMP in the EE architecture of the EJB application. The task of achieving data persistence.

Swing

Graphical User Interface (GUI) Library was originally designed to allow programmers to build a common GUI so that they can be displayed properly on all platforms. However, it is regrettable that the AWT produces a graphical user interface that is equally poor in every system, and JAVA1.2 adds the Java base class (JFC) to the old java1.0 AWT, which is part of a GUI called "Swing". Swing is the second generation of GUI development toolset, and AWT uses a specific platform-related implementation, while most swing components are not. Swing is a set of GUI components built on the upper level of AWT to ensure portability and is written in the Java language, and swing provides more complete components than AWT, introducing many new features and capabilities. Swing provides more library of components, such as: Jtable,jtree,jcombox. Swing also enhances the functionality of the components in AWT. It is because swing has so many advantages that we later use swing in development. The JComponent class is the base class for swing components, and jcomponent inherits from the container class, so all swing components are containers for AWT. Swing uses the MVC design pattern.

Learning model-View-controller MVC pattern

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.