Current location - Education and Training Encyclopedia - Graduation thesis - Can I write a paper when I study java?
Can I write a paper when I study java?
This paper introduces how to design and implement an e-commerce experimental simulation system by using JAVA open source technologies such as WebWork, Sitemesh and Hibernate, and gives the system structure, functions and implementation scheme.

Keywords e-commerce; Experimental simulation system; Java open source technology

1 Introduction

At present, it is urgent to establish an e-commerce experimental software platform in the teaching of related courses of e-commerce specialty in colleges and universities. The platform should realize the necessary software function modules including B2C, C2C, B2B, EDI, modern logistics application system, e-finance, secure electronic transaction identity authentication, etc. The rapid development of e-commerce poses a strong challenge to software development technology. Due to the complex internal logic, harsh security requirements and rapidly changing business rules of e-commerce, the development technology of e-commerce experimental simulation system is required to be powerful and flexible to meet the needs of e-commerce experimental teaching.

In the design and development of e-commerce system, there are urgent problems to be solved: maintainability, expansibility, testability, reliability, high performance and security. The current N-tier software architecture solves the above problems well. Systems are usually divided into presentation layer, business logic layer and persistent storage layer.

J2EE specification provides technical specifications for the development of multi-tier applications in terms of design, integration, performance, security and reliability, such as presentation layer, business logic framework, persistence, transaction, security and log service. At present, open source projects conforming to J2EE specifications have sprung up like mushrooms after rain, among which there are many excellent technologies. Using the existing excellent open source technology can greatly reduce the development cycle and cost of the application system, and at the same time improve the flexibility of the whole system.

2 The open source technology used in this system.

For the existing mature WEB application framework, the main problems it solves are as follows:

1) encapsulates the input data in the client web page request into a (requested) data object.

2) Verify the validity of the data in the WEB request.

3) According to different web page requests, the corresponding business logic objects are scheduled for processing, and the (requested) data objects are passed in as parameters.

4) The business logic object returns the result data object after processing the business rules.

5) Show the data in the result data object to the user through the presentation layer.

6) Persistent storage of business entities.

Open source projects such as WebWork2, Sitemesh, Hibernate, Junit, XDoclet and Ant are all mature open source projects. The design and implementation of the system make comprehensive use of the above open source technologies, and easily solve the above problems.

WebWork is a J2EE Web framework developed by OpenSymphony open source organization, which is dedicated to componentization and code reuse. WebWork consists of Xwork 1 and WebWork2***.

Xwork 1 is concise, flexible and powerful. It is a standard command mode implementation and completely separated from the web layer. Xwork provides many core functions: front-end interceptor, runtime form property verification, type conversion, powerful expression language and so on. Interceptor is like a filter net, which is used to intercept client calls and do some processing, such as checking the legitimacy of client calls, implementing security policies and supporting transactions.

WebWork2 is built on Xwork, which handles HTTP responses and requests. WebWork2 uses ServletDispatcher to turn HTTP requests into actions (business logic objects are called by the Action class to complete business processing), and realize the mapping of session and application scope, as well as the mapping of request parameters. Each action does not depend on any layer or any container. They use request and response objects through ActionContext, thus separating the WEB layer from the logical layer. WEBwork actions can be run by assigning some attribute values without starting the Web container for testing, which enhances the testability of Web components.

WebWork2 supports multi-view representation, and the view part can use JSP, Velocity, FreeMarker, JasperReports, XML, etc.

In the development of Web applications, we often face the headache problem of how to ensure the legitimacy of input data. There are two ways to verify the input data: page Java script verification and data verification before the server executes the logic code. The former is difficult to ensure system security, and is usually used as an auxiliary technology for input data verification.

WebWork uses Xwork's verification framework for verification processing, which can be activated by configuring interceptors. It can specify an xml verification file for each class that needs verification, or it can specify different xml verification files for a class in different situations. WebWork can specify the corresponding verification file for each action class, and can also specify the verification file for the attribute field of the action class. Finally, the interceptor is used to assemble the action and its verification file, which makes the logic layer not need to consider additional data verification and simplifies the business processing logic.

Sitemesh is also one of j2ee application frameworks developed by opensymphony open source organization. It is mainly used to manage the layout of web pages, and is committed to providing unified style, navigation and layout functions for large-scale websites composed of many pages. SiteMesh intercepts requests and responses through a filter, adds a decorator to the original page, and then returns the result to the client. The decorated original page does not know the decoration of SiteMesh, thus avoiding the coupling between pages caused by mutual inclusion.

This system adopts object-oriented design and implementation, and the system uses relational database to manage data, because persistent objects in the system need to be stored in relational database, which brings the mapping problem between objects and relationships. It is difficult to completely map the records of relational tables to the relationship of persistent objects, which is mainly reflected in the variety of relational mapping types of multiple tables and the difficulty in determining the number of associated data tables. It may be that a table maps multiple persistent objects and multiple tables map one persistent object. It is more likely that some fields of a table map to one persistent object and other fields map to other persistent objects. If the object uses direct database operation to access members to realize persistent object programming, then the query of the persistent object of 1: n relation to the database is actually 1+n SQL, which will inevitably lead to a significant decline in database access efficiency.

Hibernate is the best technology of persistence layer design, which gracefully solves the mapping problem of the above objects and relationships. It is open source and free, and the API is open. When its own function is not enough, it can be extended by its own coding.

Junit is used for unit testing of class modules. XDoclet and Ant are excellent open source tools to support automatic reconstruction of projects and automatic generation of documents, which can greatly improve the efficiency and quality of programmers.

3 system overall design

The main goal of the system is to realize the simulation of e-commerce system and provide a software platform for teachers and students to carry out related experiments. The key point is to simulate the business processes of all parties in trading and management under the e-commerce environment, and at the same time, it is convenient for all parties in trading to formulate corresponding business rules according to their needs. Therefore, the design of the system should be able to adapt to the changes of business rules, and it is not necessary to truly reproduce the realization of some functions, such as the realization of the security authentication service of the authentication center in the security authentication subsystem. In addition, the system should also strengthen the functional design of experimental process management, so that teachers and students can quickly grasp the process and progress of the experiment, and can automatically process the experimental results and provide relevant queries.

In an experiment, students usually play a variety of different business roles in multiple virtual enterprises. The system should provide rapid role conversion function so that students can easily understand the relationship and interaction between related operations in different business processes.

Based on the above objectives, the system is divided into two subsystems: business system and experimental system.

The business system is divided into five secondary subsystems: electronic banking system, authentication system, transaction system, enterprise business management system and logistics system. The experiment system is divided into two subsystems: student self-help system and student experiment management system.

In each subsystem, sub-modules are divided according to different operator roles, such as "trading system" (the system structure is shown in figure 1), which is divided into three subsystems: trading hall, member enterprise background management and trading center background management. In the background management of member enterprises, according to the business roles of current students, a number of enterprises involved can be listed for them to choose from. The whole system adopts single sign-on verification, which reduces the login operation of students when using each module function, avoids the problem that some popular experimental simulation systems require students to remember multiple passwords and log in repeatedly in the same experiment, makes students pay more attention to business processes, and improves the experimental efficiency.

Figure 1 trading system structure diagram

The experimental system is divided into two subsystems: student self-help and experimental management. Through the student self-help subsystem, students can inquire about the experimental tasks assigned by the teacher, the results of the experiments and the main mistakes in the experimental operation steps, so as to understand the shortcomings and improve them in time. Through the experimental management module, teachers can arrange experimental tasks, inquire about the progress and results of students' experiments, and understand the common problems in the process of students' experiments so as to guide them in time.

The analysis and design of the system adopts object-oriented UML modeling language. After fully analyzing the system requirements, the conceptual model of the system is described with UML use case diagrams and sequence diagrams, and then detailed design is carried out, the class diagram and class relation diagram of the system are described, and a preliminary data model is established. Using the collaborative modeling tool of Borland company, the bidirectional automatic conversion between system model and source code and database is realized.

In order to meet the engineering requirements of this system development, developers are divided into the following categories: A, system analysts; B, background component development programmer (mainly action class and business logic class); C. background component tester; D. Foreground user interface programmer (mainly JSP programmer+artist); E. front desk test technician. Through the combination of Sitemesh and WebWork, the independent development and testing of user interface and background components of each module are realized, which is beneficial to division of labor and cooperation, greatly reducing the time spent by developers on information exchange and improving the efficiency of system development.

4 system implementation

4. 1, operating environment

In order to adapt to the diversity of university computer system software environment, the system can run in any WEB container and the most popular relational database that conforms to J2EE specification. The open source projects Tomcat and Mysql are selected for the development of this system.

4.2 Web application configuration

Limited to space, only some key configuration information is listed. According to J2EE specification, the directory planning of this system is as follows (table 1):

Parent directory subdirectory description

/src Java class source code

Third-party class library files required by /lib system

/docs system development documentation

/ROOT WEB application root directory

/ROOT WEB-INF WEB application configuration directory

/ROOT/

WEB-INF class Java class bytecode file directory

/ROOT _decorators site grid decoration page

Table 1 system directory structure

In /ROOT/WEB-INF, configuration files such as web.xml, sitemesh.xml, decorators.xml are stored.

Configuration of WEB view layer:

This system has designed several decorative pages, and the configuration information of the main decorative pages in /WEB-INF/decorators.xml is listed below:

& ltdecorators default dir = "/_ decorators " & gt;

& ltdecorator name = " main " page = " main . JSP " & gt;

& lt mode & gt* & lt/pattern & gt;;

& lt/decorator & gt;

& lt/decorators & gt;

The layout of main.jsp, the main decoration page, has formed a popular "top left, middle right and bottom" page structure. The upper part shows the system logo and homepage links, links of major subsystems, the lower part shows the copyright statement and contact information, the left and right parts show common modules, and the middle part is the main function operation area of the current page. The main body of its JSP page is as follows:

& lttable width = " 100% " align = " center " >

& lttr & gt& lttd width=" 134" valign="top " >

& ltpage:apply decorator name = " simple "

page = "/site mesh/left . JSP "/& gt; & lt/TD & gt; & lt/tr & gt;

& lttr & gt& lttd width="488" valign="top " >

& ltpage:apply decorator name = " simple "

page = "/site mesh/middle _ top . JSP "/& gt; & ltbr & gt

& ltdecorator:body/& gt; & ltbr & gt

& ltpage:apply decorator name = " simple "

page = "/site mesh/middle _ bottom . JSP "/& gt; & lt/TD & gt; & lt/tr & gt;

& lttr & gt& lttd width=" 122" valign="top " >

& ltpage:apply decorator name = " simple "

page = "/site mesh/right . JSP "/& gt; & lt/TD & gt; & lt/tr & gt;

& lt/table & gt;

Configuration of persistence layer dormancy:

First, configure the database connection information of Hibernate through the classes/hibernate.cfg.xml file. Then, an hbm.xml file with the same name as the class is established in the directory where each class binary file needs to be persisted, and the corresponding relationship between this class attribute and the fields in the data table and the mapping relationship between classes are configured. The following is the content of Customer.hbm.xml

& lthibernate-mapping package = " com . un . eclab " & gt;

& ltclass name = " Customer " table = " Customer " >

& ltid name="id" column="CID " >

& lt generator class = "increment"/></id >

& ltproperty name = " struser name " column = " username "/& gt。

& ltproperty name = " str password " column = " password "/& gt;

& lt/class & gt;

& lt/hibernate-mapping & gt;

When you need to persist a customer object, use the following code:

Session factory sf =

New configuration (). Configure (). buildSessionFactory();

session session = SF . opensession();

transaction tx = session . begin transaction();

Customer = new customer ();

Customer.setUsername ("customer name");

customer . set password(" customer password ");

Session.save (customer);

tx . commit();

session . close();

4.3 Implementation of Business Logic Layer

Taking the trading system as an example, the main classes implemented by this subsystem are as follows (Table 2):

Class name main function

IProduct product class interface, which standardizes the main operations of product class and adapts to the requirements of different enterprises for product class.

Product product class, which realizes the Iproduct interface. Enterprises can inherit this category and manage their own products.

EccCart trading center shopping cart class, which can manage a variety of transaction types.

EccCartItem shopping car category

EccOrder order category

Options Enterprise Options Class, manage business rules.

Table 2 List of main trading system types

Through the cooperation of the above classes, the main business logic of the trading system is realized.

5 concluding remarks

Generally speaking, using open source technology to design e-commerce experimental simulation system has the advantages of short development cycle, high system flexibility, easy development and maintenance, which greatly reduces the complexity and cost of system development, can adapt to changing user needs and has broad application prospects.