Java Web Basics Tutorial (ii) Development fundamentals

Source: Internet
Author: User
Tags java web tomcat server

Java Web Basics Tutorial (ii) Development fundamentals reprint: Future Wei Lai
 Objective

The Java Web is a technical implementation of a network application based on the b\s (browser \ Server) architecture. This structured Web application is used by a large number of enterprise-class applications. As the scale of Web applications grows, the traditional Web development model cannot meet the increasingly complex business needs, so there is a more reasonable and more advanced MVC development model. There is also a series of development frameworks based on the MVC pattern, struts framework, Spring MVC and so on.

1. Development of WEB Technologies

1. First stage static website

At the beginning of web technology, due to the limitations of hardware technology most Web applications are static-based HTML pages, and some dynamic Web applications are not as smooth as they are now. Static pages can only serve as information releases, and they do not have the ability to interact.

2. Phase II Dynamic website

Applications that do not have interactive capabilities are definitely not popular. Many experts have proposed different solutions for implementing dynamic Web programs. One of the first things that was proposed was the CGI (Universal Gateway Interface), the most important of which was the ability to access the database through CGI, since almost all Web applications required access to the data. Although CGI technology is very powerful, but it also has its own shortcomings, such as the implementation of CGI program is relatively difficult technical, code difficult to maintain and so on.

3. Servlet implements Dynamic Web site

To address these legacy issues, Java introduced its own dynamic Web technology Servletin 1999.
Servlets have the following technical advantages

  1. Implementation based on Java technology
    1. Cross-platform
    2. Access to a wide range of databases
    3. Multithreading
    4. Internet
Request response Process for servlet
    1. The browser sends a request to the server
    2. Web server accepts requests
    3. Submit a request to the servlet engine
    4. The servlet engine calls the service method
    5. Returns the response to the client (corresponding code)

The servlet is the core of the entire Javaweb technology, meaning that the servlet can implement all the functions of the dynamic Javaweb program. However, if the logic of the client page is very complex, the workload of writing the servlet is very large and the code is difficult to maintain.

4. The advent of JSP

In order to solve this problem to implement the page display code writing and control logic code separation,JSP technology was born.
JSP technology can be used to mix client code and server-side code in the same page, you can directly use Java code as a server-side script.

In order to make full use of the existing servlet technology, the JSP page is translated into a servlet by the JSP engine and then processed by the servlet engine when the JSP page is accessed for the first time.

JSP page request, corresponding and run Flow 2. Java Web Technology

1. Basic components of the Java Web

A typical Java Web application should contain the following elements, package them together, and run them in a Web container.

    • Servlet
    • Java Server Pages
    • JSP standard tags (JSTL) and custom labels
    • Java classes for use in Web applications
    • static files, including HTML, images, JavaScript, and CSS
    • Describes meta information for Web applications (XML)

2. Directory structure of the Java Web

Standard directory structure
  1. UNTITLED3 is the root directory of this project.
    1. Web directory to store resource files such as Picture directory, CSS directory, JS directory, JSP files, etc.
    2. Web-inf directory for project configuration file Web. xml and Lib library files

3. Java Web configuration file

The configuration file is the backbone of all Java Web applications. The file we are introducing here is primarily the Web. xml file located in the Web-inf directory. In addition to the tomcat\conf directory there is also a Web. xml file, which is a configuration file for the Tomcat server, a global configuration.
The configuration file can be configured as follows??

  1. Servlet Context Initialization Parameters
    1. Session Configuration
    2. servlet/jsp definition
    3. Tag Library Reference
    4. MIME type mappings
    5. Welcome page
    6. Error page
    7. Security information
3. MVC Pattern and MVC framework

After extensive use of servlet/jsp technology, developers have gradually discovered the drawbacks of servlet and JSP technology.

HTML code, JavaScript, CSS and dynamic jstl, Java code mixed together is not conducive to post-maintenance, in order to solve the problem of the page and server-side code separation, which is the basic idea of the MVC pattern.

1. JSP Model 1 and JSP Model2

    • JSP Model1

Mode1 is made up of three parts

    1. client browser
    2. Server-side program (Jsp/servlet)
    3. Database
The structure of Model1

This structure also has its shortcomings, no further code-level separation.

    • JSP Model2

MVC is the abbreviation for model-View-controller

Here is the interactive diagram

The structure of Model2

The MVC pattern allows for maximum code reuse

2. Basic services in Web applications

There are many basic features that can be reused on many pages in a Web application, and we summarize the following.

    • Page navigation: This feature is best implemented in the controller
    • Page layouts: Using standard methods to implement page layouts
    • Data validation: The best way to validate data through a collection framework
    • Business logic reuse: Separating the reusable business logic from the system and forming a series of independent components makes it easy to reuse.

3. What is the MVC pattern?

The MVC pattern divides an application into 3 parts: model, view, controller, and these 3 components should be coupled as little as possible, thus improving the scalability and maintainability of the application.

    • Multiple views can correspond to multiple models
    • You can provide different data for a view through the model
    • You can add permission validation to a controller to restrict user access to sensitive resources
    • It is advantageous to extend the layers in the system by reducing the coupling between each level.

4. Common MVC Framework

    • Struts 1.x

    • Struts 2.x

    • Spring MVC

Summarize

We understand the history and development of web technologies, understand what is necessary in Web application development, and understand the important role of the MVC model in multi-person development.

Next section Trailer
    1. Html
    2. Css
    3. Javascript
    4. Ajax

Please look forward to the OH ~

Java Web Basics Tutorial (ii) Development fundamentals

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.