With the development of Web technology, the traditional enterprise-level application systems with client/server structures have gradually replaced the three-tier structure of browsers, middle layers, and back-end database servers, this structural change is embodied in both Microsoft's Windows DNA and Java-centric applications. The emergence of Servlet technology promotes the development of enterprise-level three-layer Web applications with Java as the core technology. It is most suitable for developing the intermediate layer closely related to Web servers.
1. l3 architecture solution using Servlet Technology
Enterprise-level Web applications generally include Web browsers, intermediate layers, and backend database servers.
(1) Web Browser
The Web browser is the first layer in the three-tier structure. It uses the Web browser as the client to make the customer face a unified application interface.
(2) Servlet Middle Layer
The middle layer refers to the software that runs on the server and contacts the Web browser and the background database server. Currently, technologies that can be used to implement intermediate layers include CGI, Java, and Servlet. As the Servlet is loaded by the Web server and developed using the Java language, it has made great progress in terms of performance, reliability and portability compared with CGI, therefore, Servlet is currently the most suitable technology for implementing the middle layer.
(3) Background Database Server
The backend database server stores data information. The middle layer can access the backend database through ODBC (the CGI middle layer) or JDBC (the Servlet Middle Layer.
2. Plan a three-tier Web Application
The following example uses a simple Web layer-3 Application to illustrate how to use Servlet technology to construct an intermediate layer. Here we implement a simple library management system.
(1) The user can submit the book information to the middle layer through a Web browser, and the middle layer will store the book data into the database.
(2) users can query the book information through a Web browser, and obtain the book data from the middle layer for the browser to display.
The system is a Web application with a three-tier structure, the database server uses Microsoft Access, and the middle layer is a Servlet. The system flow consists of four steps:
* The user enters the Book information on the HTML page and submits the input data to the middle-tier Book? Servlet;
* The middle-layer BookServlet constructs an SQL statement and submits the SQL statement to JDBC;
* The background database server executes the SQL statement and returns the result to the middle-layer BookServlet;
* The middle-layer BookServlet creates an HTML file based on the structure returned by the database and returns it to the client browser.
After understanding the software structure of the system, we will provide the overall system design plan:
* Design the database structure
To simplify the process, the library database contains only one table BookTable, which contains the following fields:
Column name
Type
Length
Description
Bookname
String
50
Title
Isbn
String
50
Uniform Book Number
* Design the browser HTML page
On this page, you can query the books that have been stored in the database or enter new information.
(3) design the middle layer BookServlet
The middle layer implemented by Servlet technology is "bonded" between the browser and the database server (we name it BookServlet). It creates appropriate SQL statements based on parameters passed by the browser HTML, submit the SQL statement to the back-end database server, and generate an HTML page based on the SQL statement execution result and pass it to the browser.