Java EE Enterprise Application Development A brief discussion on the first series

Source: Internet
Author: User

Do not accumulate Kuibu no to thousands of miles, not to accumulate small flow not to become Jianghai

Step1.Scenario Summary

As a Java web Developer, when developing a Web project, everyone has some of their own new experience, for the web development of some of the more classic terminology everyone will know, today we will talk about Java WEB Development in the three-tier architecture and MVC.

STEP2.the transformation of programming thinking

Recalling the individual in the Java Web Learning phase, the MVC idea was not established before, the individual in the implementation of the site user login function of the painful experience, still quite feeling, then the realization of the way now want to have to admire the courage at that time, will log on the data Access layer code, Login business logic processing code and login parameters get view forwarding control code is all soft to a servlet to deal with, of course, there is no problem in the implementation of the function, the ability to implement the user login function, the process of drawing describes the following:



Carefully consider the entire login process code implementation, found that the entire login servlet code, although the implementation of the login function, but the code processing is quite bloated, and the coupling is large, the servlet contains parameter receive, check, JDBC operation, user existence and password matching check and view forwarding control, This is tantamount to turning the servlet into a Super warrior, invincible, omnipotent, indeed a lot!

However, from the development point of view, this coding method for the subsequent development of the drawbacks also appear to be quite obvious, such as the subsequent want to join the login user points calculation (continuous login Three days, five days, such as the integration of Business add), query data to add cache processing and other new business, at this time you have to open the login servlet code , navigate to the specified code block to add new code, then test, then publish, so that although the functionality can be implemented, but the code will become more bloated, while the code of business processing becomes more and more complex, less convenient for subsequent code maintenance, the workload of this maintenance will be huge.

Then continue to analyze this process, carefully consider the current login code, the login code to split the point of view, the analysis is as follows:



You can see the current code structure by referring to this idea to split three blocks:
Web-side: Get request parameters;
Service side: Handle specific business;
JDBC side: Using JDBC for database access operations

STEP3.analysis of the three-layer thought establishment

Thus, the login code structure analysis diagram can be adjusted to:



As you can see: The legend appears complex, actually has decoupled the login servlet original code, the original proxy servlet is no longer a chatty warrior, but the separation of its responsibilities, the original login logic and JDBC access to the database operation code separation of responsibilities, The implementation of the code function decoupling, while facilitating the subsequent code maintenance operations, at this time the code becomes relatively clear, reflecting the object-oriented high cohesion, low-coupling idea, then such a code writing method in the Java world has a proper noun-three-layer architecture, the diagram is as follows:



Through the above analysis, we can see:
Processing the login process through the three-tier architecture idea to write code, the idea is very clear

    1. Interface Layer (View) is the Login form page jsp
    2. Business logic Processing

Login servlet
2.1 Receiving Login Parameters
2.2 Call service processing layer related processing method and receive processing result
2.3 Controlling Login Results View forwarding
Service
User name, password parameter check
User records queries and verifies that user records exist
Password encryption Matching
Returns the login result model data

    1. Data Access Layer

Dao Layer
Using JDBC for data access operations
Write here, presumably everyone on the three-layer structure of the understanding should be very clear, then it and the idea of MVC what is the relevance of the follow-up will be for everyone to continue to present, please pay attention to Shanghai Shang School java.

Java EE Enterprise-level application development first series

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.