Construct a three-layer Management Information System Using JSP/Servlet

Source: Internet
Author: User

Abstract: This article introduces a web-based management information system implementation framework. Using JSP/Servlet technology and MVC design patterns makes the development process more flexible and easy to maintain.

Key words: Management Information System JSP servlet MVC design mode JDBC

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, use the Program server to execute a Java Server end-to-end applet Servlet and return its output, in this way, information resources can be interacted with the client. databases servers are used to store and manage various data used in information systems, data is directly input by the database management program. The system client only needs one browser . Related personnel use the browser to query, add, modify, and delete data and manage information.
3. system design mode

The design pattern is a formal representation used by Object-Oriented programmers to solve programming problems. Currently, in most Browser/Server Web applications,BrowserDirectly interact with users through HTML or JSP to respond to user requests. Although it is intuitive, the data volume operated by most management information systems is astonishing.CodeThe increase will make the JSP page bloated, webServerThe load is too heavy. 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

DatabaseIs the core content of the management information system. CurrentlyDatabaseThere are many interface technologies, among which JDBC is a Java program connection and accessDatabaseIs a Java API that executes SQL statements. In the management information system described in this article, JSP/servlet + JDBC technology is used in data access, that is, the client does not generateDatabaseQuery commandBrowserWebServerEstablish a connection. WebServerMainly responsible for receiving local or remoteBrowserAfter receiving the request, the servlet at the intermediate layer executes the SQL statement in the program and uses the standard API provided by JDBCDatabaseAccess and 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 requestedBrowser. In this way, not onlyDatabaseServerEnd separation, while improvingDatabase.

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 languageServerEnd-to-end application development, using IBM's webshpere as an applicationServer,DatabaseThe management system selects SQL Server7.0,DatabaseThe interface 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.1DatabaseDesign

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 createDatabaseConnection. 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 callDatabaseCommand beansDatabaseInterface Method completionDatabase.DatabaseAfter the 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.

Transfer from: dynamic network Production Guide www.knowsky.com
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.