Abstract: This article introduces an implementation framework for developing Web-based management information systems. Utilizing JSP/Servlet technology and combining it with the MVC design pattern makes the development process more flexible and easier to maintain.
Keywords: Management information system, JSP, Servlet, MVC design pattern, 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 stay in an unbeatable position in the competition. MIS can not only provide information and data in a timely and comprehensive manner, simplify statistical work, and provide different reports for different management levels, but can also predict future situations based on past data. Therefore, it is particularly important to use what method to develop a management information system that takes both development efficiency and operation efficiency into account and satisfies the distributed event processing function. This article describes a method of using JSP/Servlet to build a three-tier management information system.
2. Three-tier architecture of the system
The three-tier architecture of the system is shown in Figure 1.
Figure 1 Web application architecture based on Java technology.
The entire management information system adopts the three-tier architecture of Browser/Web/DataBase. The Web server accepts the request, executes a Java server-side applet Servlet through the application server and returns its output, thereby realizing the interaction of information resources with the client. The database server is used to store various data used in the management information system, and the data is directly entered by the database management program. The system's client only requires a browser. Relevant personnel can query, add, modify, delete data and manage information through the browser.
3. System design pattern
Design pattern is a formal representation used by object-oriented programmers to solve programming problems. Currently, in most Web applications with a Browser/Server structure, the browser directly interacts with users in the form of HTML or JSP and responds to user requests. Although it is intuitive, the amount of data operated by most management information systems is staggering. As the code increases, the JSP page will become bloated and the Web server will be overloaded. Therefore, the design pattern based on 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. In specific implementation, Servlet is used as the controller of the application, JSP document is used as the view, and JavaBeans is used to represent the model. All requests are sent to the Servlet as a controller, which accepts the requests and responds by dispatching them to the appropriate JSP based on the request information. At the same time, Servlet also generates JavaBeans instances according to JSP requirements and outputs them to the JSP environment. JSP can get the data in JavaBeans by directly calling methods or using UseBean's custom tags. This design pattern effectively separates the data layer from the presentation layer, making development work easier and faster. In this design mode, the data transfer between various levels is shown in Figure 2.
Figure 2 Data transfer of MVC design pattern Figure
4. Data access technology
The 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 programming interface for Java programs to connect and access databases. It consists of a set of classes and interfaces written in Java language and is a Java API for executing SQL statements. In the management information system introduced in this article, JSP/Servlet+JDBC technology is used in data access, that is, the client does not generate database query commands, and the browser on the client establishes a connection with the middle-tier Web server through the URL. . The web server is mainly responsible for receiving HTTP data requests from local or remote browsers. Then, after the Servlet in the middle layer receives the request, it uses the standard API provided by JDBC to access the database and perform corresponding operations by executing the SQL statements in the program. The Servlet then passes the query data to JSP, and finally generates a standard JSP page and returns the results to the requesting browser. In this way, it not only separates the client from the database server, but also improves the efficiency of database access.
5. Example
In order to better illustrate the method of using JSP/Servlet to build a three-tier management information system, the author will take an example to analyze and design a commodity mail order management information system. This commodity mail order management information system uses Java language to develop server-side applications, and uses IBM's Webshpere as the application server. The database management system uses SQL Server7.0, and the database interface program uses the JDBC2 interface. The entire system uses a Web-based approach to realize customer management, staff management, order management, commodity management, outbound management, inbound management and other business processing, process control, authority control, query statistics, and printing functions of the mail order business. It analyzes the query function of the order management part in detail.
5.1 Database design
For the order part, the order information table Db_order needs to be defined. The fields in the table include order number (ddbh), customer number (khbh), product number (spbh), product unit price (spdj), and order quantity (dgsl) , total price (hjzj), amount received (sdje), date received (sdrq). In order to use the Db_order table in the application, a database connection must be established. This function is implemented by sql_data.java. Part of its 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 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 process of the commodity mail order management information system, based on the idea of MVC design pattern and combined with the actual situation of the system, we further divided the Model layer according to the division of labor. The Model layer is generally composed of many JavaBeans. According to the different roles these Beans play in the system, they are divided into three types: Command Beans, Data Beans, and View Beans. Among them, Command Beans are used to implement business logic, that is, the processing of object instances; Data Beans are used to describe and define object models abstracted from the real world; and View Beans are used to further encapsulate and return processed object instances. to the client.
First, Command Beans obtains the information passed by the Servlet, encapsulates the business information in object instances defined by Data Beans, and processes the information according to business logic. When a database access operation needs to be called, Command Beans uses the object instance and corresponding control information to complete the database operation through the database interface method. After the database operation is completed, the returned record set is encapsulated into an object instance of Data Beans. After certain processing, the information that needs to be returned to the interface is encapsulated into predefined View Beans, and the information is returned through View Beans. to the interface.
The following is part of the code of OrderGl.java that queries and processes orders.
public class OrderGl {
…
//Define the following method to complete the order query operation
public final String currentMultiQuery(
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws com.goods.exception.GoodsException
{
//Get the corresponding query information from the JSP page
com.goods.view.OrderView view = getView(request, response);
String ddbh = view.getDdbh(); //Order number
//Generate SQL statement
String sqlQuery = "select ddbh,khbh,spbh,spdj,dgsl,hjzj,sdje,sdrq from db_order ";
//Execute 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.executeQuery(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();
}
//Echo the relevant information to the interface view.setVct(vector);
request.setAttribute("view", view);
return "1";
}
}
5.3 The client design
view is the part of the application that displays information to the user, that is, the Web page returned to the user after the user makes a request. When the "Query" button is clicked, the order information result page ordercx.jsp obtained based on the order number will be displayed. This is done using the following syntax in 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 each existing object, and then passes <%=view.getDdbh()
and <%=temp.getDdbh()%> to obtain related data.
6. Summary
This article proposes a solution for developing a Web-based three-tier management information system using JSP/Servlet technology. This solution realizes 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 management information systems.