Building three-tier management information system with JSP

Source: Internet
Author: User
Tags implement interface object model query tostring client
JS 1, Introduction

Management Information System (MIS) is a system of collecting, transmitting, storing, processing and using information, which is composed of people, computers and so on. With the development of science and technology and the expansion of information, Enterprise Informatization has become one of the effective means of Enterprise's unbeaten position in competition. MIS can not only provide information and data in a timely and comprehensive way, simplify the statistic work, put forward different reports to different management levels, but also predict the future situation according to the past data. Therefore, it is very important to develop a management information system which takes into account the development efficiency and operational efficiency, and satisfies the distributed event processing function. This paper describes a method of constructing three-layer management information system using Jsp/servlet.

2, the system three-tier architecture

The three-tier architecture of the system is shown in Figure 1.


Figure 1 Web application architecture based on Java technology

The whole management Information system adopts the browser/web/database three-layer architecture. The Web server accepts the request, executes a Java server-side applet servlet through the application server, and returns its output to enable interaction with the client for information resources. The database server is used to store the various data used in the management information system, and the data is entered directly by the database management program. The client of the system needs only one browser. Related personnel through the browser to query, add, modify, delete data, the information management.

3, the system design mode

Design pattern is a formal representation of object-oriented program designers to solve programming problems. Currently, in most Browser/server architecture Web applications, browsers interact directly with the user in the form of HTML or JSP, responding to user requests. Although very intuitive, but most of the management information system operation of the data volume is amazing, as the code increases will make JSP pages bloated, Web server overload. Therefore, the design pattern based on Model View Controller (Mvc.model-view-controller) is adopted on the intermediate layer. The model layer is used to implement the business logic, the view layer is used to display the user interface, the controller layer is mainly responsible for the control relationship between the view layer and the model layer. When implemented, the servlet is used as the controller of the application, and the JSP document is used as a view, and JavaBeans is applied to represent the model. All requests are sent to the servlet as the controller, which accepts the request and sends them to the appropriate JSP to respond to the request information. At the same time, the servlet generates JavaBeans instances and outputs them to the JSP environment based on the requirements of the JSP. The JSP can get the data in the JavaBeans either by calling the method directly or by using a Usebean custom tag. This design pattern realizes the separation of the data layer and the presentation layer well, and makes the development work easier and faster. In this design pattern, data transfer between levels is shown in Figure 2.


Figure 2 Data transfer diagram of MVC design pattern

4. Data access Technology

Database is the core content of management information system. At present, there are many web and database interface technologies, in which JDBC is the application interface of Java program connecting and accessing database, consisting of a set of classes and interfaces written in the Java language and a Java API for executing SQL statements. In the management information system introduced in this paper, the JSP/SERVLET+JDBC technology is adopted in the data access, that is, the client does not produce the database query command, and the browser on the client establishes the connection through the URL and the middle-tier Web server. The Web server is primarily responsible for receiving HTTP data requests from local or remote browsers, and then the middle-tier servlet receives the request and uses the standard APIs provided by JDBC to access and manipulate the database through executing the SQL statements in the program. The servlet then passes the queried data to the JSP, and finally generates a standard JSP page that returns the results to the requesting browser. This will not only separate the client from the database server, but also improve the access efficiency of the database.

5. Example

In order to better illustrate the method of constructing the three-layer management information system with Jsp/servlet, the author will give an example to design a commodity order management information System. This mail order management information system uses the Java language for server-side application development, uses IBM's Webshpere as the application server, the database management system chooses the SQL Server7.0, the Database interface program uses the JDBC2 interface. The whole system uses web-based way to realize the functions of customer management, staff management, order management, commodity management, management, management, flow control, permission control, query statistics and printing. Detailed analysis of the Order Management section of the query function.

5. 1 Database Design

For the order section, you need to define the order Information table Db_order, the fields in the table have order number (DDBH), customer number (KHBH), commodity number (SPBH), Commodity Unit Price (SPDJ), order quantity (DGSL), total Total Price (HJZJ), Amount received (Sdje), Date of receipt (SDRQ). In order to be able to use the Db_order table in the application, a database connection must be established. This feature is implemented by Sql_data.java. Part of the code is as follows.

public class Sql_data {

String url = "Jdbc:odbc:PostOrder"; Use your hostname and port
String login = "sa"; Use your Login
String password = "zh12345"; Use your password
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-tier design

In the process of the development of commodity order management Information system, based on the idea of MVC design pattern and 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, according to the different roles of these Beans in the system, they are divided into command Beans, Data Beans, View Beans three kinds. Where command beans is used to implement business logic is the processing of object instances; Data beans is used to describe and define an object model that is abstracted from the real world, whereas View beans is used to further encapsulate the processed object instances and return them to the client.

First, Command beans obtains the information that the servlet delivers and encapsulates the business information in the object instance defined by the data beans, processing the information according to the business logic. When an access operation is required to invoke the database, Command beans completes the operation of the database through the database interface method with the object instance and the corresponding control information. After the database operation is completed, the returned Recordset is encapsulated into an object instance of data beans, and after some processing, the information that needs to be returned to the interface is encapsulated into the predefined view beans, and the information is returned to the interface through view beans.

Here are some of the code for the Ordergl.java of the Order query processing.

public class Ordergl {
......
Define the following methods to complete the query operation on the order
Public final String Currentmultiquery (
Javax.servlet.http.HttpServletRequest request,
Javax.servlet.http.HttpServletResponse response)
Throws Com.goods.exception.GoodsException
{
Get the appropriate query information from the JSP page
Com.goods.view.OrderView view = GetView (request, response);
String DDBH = VIEW.GETDDBH (); Order number

Generate SQL statements
String sqlquery = "Select Ddbh,khbh,spbh,spdj,dgsl,hjzj,sdje,sdrq from Db_order";
Perform query operations
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 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 the user, which is the Web page that the user returns to the user after making a request. When you click the Query button, the Order Information results page ordercx.jsp is displayed based on the order number. 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 > Actions use ID and scope to discover the existence of each object, and then pass &LT;%=VIEW.GETDDBH ()
and &LT;%=TEMP.GETDDBH ()%> to get the relevant data.

6. Summary

This paper presents a solution to develop a three-tier management information system based on Web, which utilizes Jsp/servlet technology. The scheme realizes the separation of the presentation layer and the logic layer, makes the system have a good expansibility, and provides a complete idea and method for the development of MIS.



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.