Research on Web application framework based on MVC design pattern

Source: Internet
Author: User
Summary

The MVC design pattern is the preferred pattern for J2EE-based Web application development. Many popular frameworks are also based on the MVC design pattern. This article briefly introduces the MVC design mode and struts
Framework, and a new Web Application Development Framework-webframework based on MVC model is proposed. The composition and functions of the framework are described in detail.

  Keywords
MVC design pattern; J2EE; Framework; struts

  Introduction

 
With the rise of open-source software, various frameworks have emerged, such as Apache
Struts is a typical example. Using these frameworks in actual software development greatly reduces the complexity and difficulty of J2EE development and reduces development costs. However, these frameworks are also insufficient.
Such as difficult to master and complicated configuration. The purpose of this study is to design a simple web development framework-webframework and webframework structure definition.
Scalable, easy to understand, increase system scalability, maintainability, and reduce development costs.

  MVC design pattern

J2EE-based
Most Web application systems use the MVC pattern to implement their architecture. MVC (Model-View-Controller) was a programming language in 1980s.
A software design mode invented by Smalltalk-80. In MVC mode, interactive applications are divided into model, view, and controller.
Part [1]. A model refers to an object model mined from the real world and reflects the application logic. The model encapsulates data and operations on data, which is the place where data is actually processed and computed. View is an application and
Interfaces between users, which are responsible for displaying applications to users and displaying model statuses. The Controller is responsible for the interaction between views and models, and controls the response methods and processes for user input.
Actions: distribute user requests to the corresponding model, and promptly respond to changes in the model to the view. MVC separates these objects to improve flexibility and reusability. The structure 1 of the MVC mode is shown below:


Figure 1 Structure of the MVC design pattern

  Struts Framework

 
Struts is an open project of the Apache Foundation Jakarta project team.
Source Project, which uses the servlet2.2 and jsp1.1 tags as part of the implementation. It consists of a group of collaborative classes, Servlet and JSP tags to form a reusable
System design. It helps Java developers develop web applications using J2EE. It gives full play to the "separated display logic and business logic" in the design mode. Therefore, more and more
The development of large-scale Web application projects all adopt the Struts framework, or use the struts Architecture Design for the development of application systems based on the MVC model.

The working principle of struts 2 is as follows:


Figure 2 Working Principle of struts

Struts has two advantages: Form Verification and page navigation. Form Verification solves the problem of verifying request data and enhances the system robustness. The page navigation makes the business process of the system clear, and the links between various parts of the system can be reflected through the configuration file, which simplifies the maintenance work of the system to a certain extent.

However, Struts also has some shortcomings:

1) steep learning curve. Taglib is the struts tag library. If it can be used flexibly, it can greatly improve the development efficiency. However, for beginners, a continuous learning process is required, increasing the development cost of the system.

2) increases the complexity of the system. The coupling between the business layer and the performance layer is too high, so developers cannot focus on the design and implementation of the Performance layer.

3) There is no solution for front-end verification of form data, which is not conducive to use in large systems.

4) the configuration file is too complex and complex, with the increase of the system scale, the struts-config.xml becomes more and more huge, and the maintenance becomes more and more difficult.

  Webframework

 
In view of the above shortcomings of the Struts framework, this article proposes the webframework framework. Compared with the Struts framework, webframework is easier to use.
The presentation layer is designed to reduce development difficulty and reduce development costs. VO (Value
Object) as a way of data transmission, reduce system complexity; use simple browser-side form field data verification to improve system operation efficiency; Simplify the configuration file to facilitate system maintenance.

  Design Objectives

 
Following the J2EE specification and based on the multi-layer Distributed Application Software Development Framework, the distributed Hierarchical architecture can improve the scalability of the software system. In the long term, it ensures that the customer invests in the current software.
The software system can also provide services normally in case of exceptions to improve the stability of the software system. The logical separation of different structural layers is conducive to the collaborative work of team members in the software development process, improve Production Efficiency
Rate.

2. Framework Structure

In the design strategy, the software system is divided into the data layer, the business logic layer and the presentation layer from the framework, mainly in the business presentation and business
Service logic layer. The presentation layer of a common three-tier architecture is subdivided into the view format layer and the presentation control logic layer. The presentation layer involves the server representation and corresponding interactive control logic in the user view format based on the "thin customer" technology.
The view format layer only retains the necessary display formats and event triggers for building the client user view. In the presentation control logic layer, as described by the name, implements the control logic and some business sessions required for human-computer interaction.
Logic, coupled with the business entities that run through all the system logic layers, forms the presentation layer architecture with the MVC mode as the core, the display format, display control logic, and model data are effectively separated.
Strong scalability of the system architecture and pluggable application subsystem.

The business layer is subdivided into the business Session Layer and business persistence layer. The business layer processes logic componentized seals in the business process.
And has nothing to do with the data layer platform and external systems. The business Session Layer focuses on business activities, encapsulates all activities of a business in a transactional manner, and ensures the consistency and efficiency of business process processing.
The Jiuhua layer provides support for the business Session Layer, provides persistent operations on business data, and establishes a separate middle layer between the business and the database to form a loosely coupled architecture.

The MVC design mode is implemented in this layered model. The servlet component corresponds to the Controller part in MVC, and JSP and browser correspond to the view part, the session appearance, logical bean, and value object correspond to the model section. Its structure 3 is shown below:

2.1 data layer

(1) layer Definition

The data layer manages data and provides standardized open access interfaces to the business logic layer.

 
The data layer currently provides two types of services: database and file. Databases mainly provide storage and access services for business operation data and other data with obvious structural characteristics; files mainly provide
It includes storage and access services for unstructured data, such as scanning document images, faxes, photos, computer-generated reports, word processing documents, workbooks, presentations, voice and video clips.

Main functions: Data creation, data storage, data query, data update, data deletion, data security, transaction support, and data backup/recovery.

(2) interfaces with other layers

1) The data layer of the database mode provides the database access service interface to the business logic layer, and the business logic layer accesses the Database Service through the JDBC protocol.

2) The data layer of file mode provides a file-level access service interface to the business logic layer, and the business logic layer accesses file data through the file access API provided by the operating system itself.


Figure 3 myframework Framework Structure

2.2 business logic layer

(1) layer Definition

 
The business logic layer accepts user requests input from the presentation layer, converts them into a way that the business logic process can understand, and sends data requests to the data layer in an orderly manner according to the specific business logic, and the data returned by the data layer
Interpreting and combining the information required by the user and returning it to the presentation layer is the core of business logic implementation and processing in the entire application software system. The business logic layer runs on the EJB and web containers based on the J2EE application server.
.

(2) component Definition

The business logic layer contains the session appearance (Session fa? Ade, logic bean, and data access bean.

1) Session appearance

Provides a unified service logic calling interface for the presentation layer. It is the boundary of data access transactions, and all data access transactions are managed by the session appearance, that is, the appearance of a session is responsible for starting and closing data access transactions.

Business Logic completion method: Call the logical bean to implement business logic.

2) logic Bean

It provides specific implementation of business logic and is reusable: it can be called directly by the session appearance to implement the business logic required for the session appearance; it can be called by other logic beans, in this case, the logic bean is an integral part of a more complex business logic.

Business Logic completion method: You can call other logic beans to implement relatively complex business logic. You can directly call the data access bean to complete relatively simple business logic.

3) Data Access Bean

Provides an access interface for the data layer. It is not responsible for managing transactions. It only passively uses the transaction environment passed in by the caller. It is mapped to the database table, generally, a single data table maps to a single data access bean. A single data access bean contains all relevant data access operations corresponding to a single data table.

4) Value Object

 
Contains the attributes of the business logic entity, excluding the operations of the business logic entity. It is the main unit of data exchange between the presentation layer and the business logic layer, and forms a complete business logic entity together with the session appearance, provides a Business License
The unified interface from the logic layer to the presentation layer. The ing mode to the database table usually adopts the ing mode of a single data table corresponding to a single value object; A new value object can be aggregated with different types of value objects.

(3) interfaces with other layers

1) The Service Logic calling interface for the presentation layer is provided by the session appearance, and the presentation layer accesses the business logic layer through local Java calls.

2) the data access bean accesses the Database Service through JDBC.

3) the data access bean accesses file data through the system service provided by the operating system.

2.3 presentation layer

(1) layer Definition

The presentation layer accepts input requests submitted by users. By accessing the business logic layer, the presentation layer obtains and outputs visual responses to users.

(2) component Definition

The MVC design mode is used. servlet provides overall control over page requests and request responses. jsp and browser provide visual display of request results.

1) Servlet

Receives all business requests submitted by users through a browser, merges corresponding value objects, and accesses the business logic layer to complete business processing of business logic entities; the changes to the business logic entities are notified in the form of value objects and switched to the corresponding JSP.

2) JSP

The final output format text (HTML) of the Request Response result is merged based on the value object notified by the servlet. The synthesized and formatted text is sent to the user's browser that submits the business request using the network protocol.

3) Browser

Provides an interface for users to input business request data. After the data verification is passed, the system submits business requests. It receives the HTML text of the business request response and presents the business request response results to users in a visualized manner.

4) WebService

It is the boundary and interface that the business logic layer provides to external systems for integration and interaction with external systems.

(3) interfaces with other layers

1) servlet accesses the business logic layer through Java local calls.

2) the browser sends a business request to the presentation layer through HTTP/HTTPS protocol and receives the business response from the presentation layer.

3. Framework configuration file

(1) system initialization configuration file: Web. xml

This file is the configuration information file exclusive to the Controller. When the controller starts for the first time, it needs to load the system configuration information from this file. The file content is as follows:

<Servlet>
<Servlet-Name> controlservlet </servlet-Name>
<Servlet-class> mytools. Control. Web. controlhan-Dler </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> controlservlet </servlet-Name>
<URL-pattern>/controler </url-pattern>
</Servlet-mapping>

(2) page navigation configuration file: web_config.xml

<? XML version = "1.0" encoding = "gb2312"?>
<Web-config>
<Forwards>
<Forward name = "XX" Path = "filename. jsp"/>
............
</Forwards>
<Action-mappings>

<Action name = "XX" type = "actionclassname" method = "methodname"/>
............
</Action-mappings>
</Web-config>

 
The web_config.xml file is an important part of the framework. It controls the execution process during system execution. This file contains two elements: <forwards> and <action-
Mappings>, where the <forwards> element is used to set the JSP page to be switched to the call, and <action-mappings> sets the operation submitted by the current user.
The action class to be called and the method in the current class.

  Summary

The webframework has been tested and tested in a shipping management project. Practice has proved that this framework can shorten the development cycle, improve development efficiency, and ensure stable system operation in medium and large projects, easy to maintain.

The research on the application development framework is a process of continuous in-depth and gradual improvement. Based on the continuous promotion and trial use of the webframework, it will further expand its functions to make its application more extensive.

Quick Search of technical articles

Topic navigation
Software Applications
· Operating System · Anti-virus and anti-Black · Application Software
· Chat software · Network Software  
Web Development
· ASP · Javascript · CGI
· JSP · VBScript · Web Server
· PHP · XML  
Development language
· VB · VC · ASP. NET
· Java · C/C ++ · Delphi
Database development
· MySQL · SQL/Access · PowerBuilder
· Oracle · DB2  
Website Design
· Flash · Dreamweaver · Html/CSS
· Fireworks · Frontpage  
Graphic Design
· Photoshop · CorelDraw · AutoCAD
· Freehand · Illustrator · 3dsmax
Media Animation
· Director

· Authorware · Maya
· Video Processing    

Product library recommendation

· Notebook · Desktop · Server
· Digital cameras · Mobile Phone · GPS
· DV camera · MP3 · MP4
· CPU · Hard Disk · Memory
· Motherboard · Graphics card · Display
· Printer · Projector · Vro

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.