Use JSP to build a three-layer Management Information System

Source: Internet
Author: User

1. Introduction

Management Information System (MIS) is a system composed of people and computers that can collect, transmit, store, process and use information. With the development of science and technology and the expansion of information, enterprise informatization has become one of the effective means for enterprises to remain undefeated in the competition. MIS not only provides information and data in a timely and comprehensive manner, simplifies statistics, and provides different reports for different management levels, but also predicts future conditions based on past data. Therefore, it is particularly important to develop a management information system that takes both development efficiency and operation efficiency into account and meets the Distributed Event processing function. This article describes how to use JSP/servlet to build a three-tier management information system.

2. Three-tier architecture of the system

System's three-tier architecture 1.


Figure 1 Java-based Web application architecture

The entire management information system adopts the Browser/Web/database three-tier architecture. The Web Server accepts the request and executes a Java server-side applet Servlet and returns its output through the application server, so as to implement information resource interaction with the client. The database server is used to store various data used in the management information system. Data is directly input by the database management program. The system client only needs one browser. Related Personnel query, add, modify, and delete data through a browser, and manage information.

3. System Design Model

The design pattern is a formal representation used by Object-Oriented programmers to solve programming problems. Currently, in most Browser/Server Web applications, browsers directly interact with users through HTML or JSP to respond to user requests. Although intuitive, most of the data volumes used to manage information system operations are astonishing. As Code increases, JSP pages will be bloated and web servers will be overloaded. Therefore, the design mode based on the model View Controller (MVC. Model-View-Controller) is adopted on the middle layer. The model layer is used to implement business logic, the view layer is used to display the user interface, and the Controller layer is mainly responsible for the control relationship between the view layer and the model layer. Specifically, servlet is used as the application controller, JSP document is used as the view, and JavaBeans are used to represent the model. All requests are sent to the Controller servlet, which accepts the requests and distributes them to the appropriate JSP for response based on the request information. At the same time, Servlet also generates JavaBeans instances Based on JSP requirements and outputs them to the JSP environment. JSP can call the method directly or use the custom tag of usebean to obtain data in JavaBeans. This design mode achieves the separation between the data layer and the presentation layer, making development easier and faster. In this design mode, data transmission between different layers is 2.


Figure 2 data transmission in the MVC design mode

4. Data Access Technology

Database is the core content of the management information system. Currently, there are many web and database interface technologies. Among them, JDBC is an application interface for connecting Java programs and accessing databases. It consists of a group of classes and interfaces written in Java, is the Java API for executing SQL statements. In the management information system described in this article, JSP/servlet + JDBC technology is used for data access, that is, the client does not generate database query commands, the browser on the client establishes a connection with the Web server on the intermediate layer through the URL. The Web server is mainly responsible for receiving HTTP data requests from local or remote browsers. After receiving the request, the servlet at the intermediate layer executes the SQL statement in the program, use the standard APIs provided by JDBC to access the database and perform corresponding operations. The servlet then transmits the queried data to the JSP, and finally generates a standard JSP page to return the result to the requesting browser. This not only separates the client from the database server, but also improves the database access efficiency.

 

 

 

 

5. Instances

To better illustrate how to use JSP/servlet to build a three-tier management information system, the author will give an example to analyze and design a product Mail Order Management Information System. This product Mail Order Management Information System uses Java language for server-side application development, using IBM's webshpere as the application server, the database management system selects SQL Server7.0, and the database interface program uses the jdbc2 interface. The entire system uses Web-based methods to implement business processing, process control, permission control, and query of mail order businesses, such as customer management, employee management, order management, product management, warehouse management, and warehouse receiving management. statistics, printing, and other functions. The query function of the Order Management Section is analyzed in detail.

5.1 Database Design

For the order part, you need to define the order information table db_order. The fields in the table include Order Number (ddbh), customer number (khbh), product number (spbh), and product unit price (spdj ), order Quantity (dgsl), total price (hjzj), received amount (sdje), received date (sdrq ). To use the db_order table in an application, you must establish a database connection. This function is implemented by SQL _data.java. Some of the Code is as follows.

Public class SQL _data {

String url = "JDBC: ODBC: postorder"; // use your hostname and port number here
String login = "sa"; // use your login here
String Password = "zh12345"; // use your password here
Public connection = NULL;
Public Statement ST = NULL;
Public resultset rs = NULL;
Try
{
Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver ");
Conn = drivermanager. getconnection (URL, user, password );
} Catch (exception E)
{
E. printstacktrace ();
}
}

5.2 Middle Layer Design

In the development of the product mail order management information system, based on the MVC design pattern, combined with the actual situation of the system, we further divide the model layer according to the division of labor. The model layer is generally composed of many JavaBeans, which are divided into command beans, data beans, and view beans based on their roles in the system. Command beans are used to implement business logic, that is, to process object instances; Data beans are used to describe and define object models abstracted from the real world; view beans further encapsulate the processed object instances and return them to the client.

First, command beans obtains the information passed by Servlet, encapsulates the business information in the object instance defined by data beans, and processes the information according to the business logic. When you need to call the database for access operations, command beans uses the database interface method to perform operations on the database through the object instance and corresponding control information. After the database operation is complete, encapsulate the returned record set into an object instance of Data beans. After some processing, encapsulate the information that needs to be returned to the interface into the view beans defined in advance, and return the information to the interface through view beans.

The following is part of the ordergl. Java code for order query.

Public class ordergl {
......
// Define the following method to query orders
Public final string currentmultiquery (
Javax. servlet. http. httpservletrequest request,
Javax. servlet. http. httpservletresponse response)
Throws com. Goods. Exception. goodsexception
{
// Obtain the query information from the JSP page
Com. Goods. View. orderview view = getview (request, response );
String ddbh = view. getddbh (); // Order Number

// Generate an SQL statement
String sqlquery = "select ddbh, khbh, spbh, spdj, dgsl, hjzj, sdje, sdrq from db_order ";
// Perform the query operation
Java. util. Vector vector = new java. util. vector ();
Com. Goods. SJK. SQL _data per = new COM. Goods. SJK. SQL _data ();
Try
{
Java. SQL. resultset rs = per.exe cutequery (sqlquery );
While (Rs. Next ())
{
Com. Goods. dx. db_order temp = new COM. Goods. dx. db_order ();
Temp. setddbh (Rs. getstring ("ddbh "));
Temp. setkhbh (Rs. getstring ("khbh "));
Temp. setspbh (Rs. getstring ("spbh "));
Temp. setspdj (Rs. getstring ("spdj "));
Temp. setdgsl (Rs. getstring ("dgsl "));
Temp. sethjzj (Rs. getstring ("hjzj "));
Temp. setsdje (Rs. getstring ("sdje "));
Temp. setsdrq (Rs. getstring ("sdrq "));
Vector. addelement (temp );
}
Rs. Close ();
Per. Close ();
} Catch (throwable E)
{
E. printstacktrace ();
Per. Close ();
Cxyw. printerrortoweb (request, response, E. tostring ());
Return e. tostring ();
}
// Display relevant information back to the interface
View. setvct (vector );
Request. setattribute ("View", view );
Return "1 ";
}
}

5.3 client Design

A view is part of an application that displays information to users, that is, the web page that the user returns to the user after sending a request. When you click "query", the order information result page ordercx. jsp is displayed based on the order number. This is done using the following syntax on the JSP page:

<JSP: usebean id = "View" class = "com. Goods. View. orderview" Scope = "request"/>
<JSP: usebean id = "Temp" class = "com. Goods. dx. db_order" Scope = "page"/>
<JSP: usebean> the Action uses ID and scope to discover existing objects, and then uses <% = view. getddbh ()
And <% = temp. getddbh () %>.

6. Summary

This article proposes a solution for developing a web-based three-layer Management Information System Using JSP/Servlet technology. This solution achieves the separation of the presentation layer and the logic layer, making the system highly scalable. At the same time, it provides a complete idea and method for the development of the management information system.

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.