Analysis of e-commerce website instance based on Java EE

Source: Internet
Author: User
Tags contains interface key query reference require web services access
J2ee| e-commerce Summary:In this paper, an example is given to analyze the whole process of using the technology architecture of Java EE to build an enterprise-Class e-commerce website, and to analyze the key parts and related technologies, and to put forward a lot of valuable ideas and methods combined with the author's experience.

   one. Preface:

In recent years, with the rapid development of Internet business, e-commerce between enterprises, enterprises and consumers has become possible, the establishment of enterprise-level E-commerce platform can not only broaden the marketing channels of enterprises, but also to enhance the brand image of enterprises have important strategic significance.

This article will take the current domestic largest service trading platform, such as Easy Network (http://www.routease.com/) as an example, in-depth analysis of an E-commerce trading platform to build the whole process.

The preparation of the article

The implementation of a project first determines the project objectives, project requirements and development environment (for ease of understanding, such as easy network as a project to describe). This article mainly discusses these three aspects:

I. Implementation OBJECTIVES

such as easy to establish the goal of the network: the construction of the largest service-class trading platform and online work platform. As the main technical explanation, if you want to know more background information, you can visit: http://www.routease.com/AboutUs.htm.

Two. Implementation requirements

The goal is to determine the requirements, and to tailor clearly defined project requirements is key to the success of the project. You can use the Rose tool to create a Project object entity diagram, which is no longer detailed here, and here are some descriptions of several important objects: (You can view the following with http://www.routease.com/):

Totradeentity: Transaction entity object. The object is the core object that identifies the service object for the transaction. such as translation services, unlocking services.

Servicerequirement: Service Demand object. This object identifies the user requirements. such as the need for computer maintenance information.

Shop: The object of the store. The object for small and medium-sized enterprises or individuals open shop, a shop corresponding to a number of transaction entities.

User: Object. This object identifies a legally registered user who is engaged in a Web site and retains user information.

Account: Accounts object. This object identifies the user's account information.

Message: Messages object. This object identifies the information exchanged between users.

Credit: The credibility of the object. This object identifies the credit rating information of the user transaction and provides a powerful reference for the transaction.

Three. Development/Operation Environment

Based on the above requirements analysis, this site adopts j2ee/structs application architecture, server host uses WIN2003 server+apache2.0.54+tomcat 5.5.4 system Environment, development environment: eclipse+ JDK1.5, the famous ORM tool TopLink9.0.4.5 used by the database DAO. The following is a brief introduction to the corresponding development techniques and their tools:

1. Structs Technology

The development of Web applications has undergone a process of development by Peer-to-peer (page to page) and MVC (Model View controller). Earlier Web applications processed and responded to user requests on the page, as shown in Figure 1-1, which is the JSP1.0. The greatest advantage of such a web architecture is the high efficiency of development, and then in recent years, with the rapid development of the Internet, the Web site function is increasingly enhanced, and this Peer-to-peer Web site architecture (because its business Rules code and page code mixed into a group, not conducive to maintenance) has no longer adapt to the development of Instead, the MVC based Web architecture. The core idea of MVC is to divide the application into three parts: model, view and controller. The model refers to the data of the application and the operation of the data; The view refers to the user interface; Controller is responsible for the synchronization between the user interface and the program data, which is to complete the two-direction action: A. Complete the update of program data (model) based on user interface (view) operations B. Change the process data (model) to the user interface (view) in a timely manner. Through MVC's web architecture, can weaken the coupling relationship between the various parts, and the business logic processing and the page and data separation, so that when one of the modules of the code changes, does not affect the normal operation of other modules, so based on MVC Web architecture more suitable for large-scale software application development trend.


Figure 1

Figure 2

At present, the development framework based on MVC mainly includes structs, spring and so on. This station chooses the structs as the development frame, uses the structs application framework to develop the application program, frees the developer from the tedious code establishment, replaces is configures some contains the corresponding relation the XML file, thus when the application environment changes, does not need to recompile the program to be able to run, And make the application more flexible, efficient, and high degree of reuse.

From the development point of view, struts mainly has the following functions:

• Contains a controller servlet that sends a user's request to the appropriate action object. The Web.xml file is used to configure its associated parameters.

Tag Library, and provides associated support in the controller servlet to help developers create interactive form applications.

• Associate the Action object with the user request and the request results page by configuring the Structs-config.xml file.

For more information about structs, please contact the official website: http://jakarta.apache.org/struts

2. TopLink Technology

In the past, access to model data was often directed to accessing databases through database interfaces such as ODBC. But such processing is not in the spirit of OOP, and application developers must be familiar with the model structure of the background database, which makes development more difficult. For this reason, ORM (Object Relational Mapping) technology came into being. ORM technology is actually a framework of object persistence, whose core idea is to establish the mapping relationship between Java object and background database. This access to these Java objects is actually access to the back-end database, which masks the details of database access, and developers can even develop without understanding the background database. In addition, TopLink also has a good performance in data cache optimization. This project is developed using the famous ORM tool TopLink.

   the implementation of the article

This article mainly introduces the concrete realization process of the platform. According to the relevant theory of software engineering, combined with the author's years of development experience, web site development generally follow the following six steps:

1. Collect and organize the website requirement.

2. According to the requirements of the website, visualize the interactive situation of the Web page (i.e. use case) and design the prototype of the website (Prototype).

3. Design the instantiation object and the background database structure.

4. An ORM tool is used to establish the mapping relationship between the instantiated object and the background database.

5. Customize the background action to handle user actions according to the website interaction requirements.

6. Modify the site prototype (Prototype) as a dynamic page (JSP file), the action processing results embedded in the dynamic page returned to the client.

In these six steps, the first step is actually already given in the preparation article, which focuses on the following steps.

1. Website prototype (PROTOTYPE)

Site prototype is a Web site features a page-level description, that is to see the original site is like to see a real site, just like the original site does not embed dynamic code, and the lack of links between the pages.

The development of the website prototype is the development of the Pure static page, the key of making the website prototype is to transform the function requirement into Man-machine interface.

such as easy to Web site prototype production download address:Http://www.routease.com/download/ruyinew924.rar

2. OOP design and background database design

With powerful ORM development tools, OOP and database design can be done simultaneously (that is, 3, 4 steps of the above step can be implemented simultaneously), which is the most important feature of ORM tools. This project uses Oracle company TopLink as an ORM development tool. The following is a brief introduction to the TopLink development process.

1 Open the TopLink Mapping Workbench component, and then create a new mapping project.

2 Configure the properties of the project, which is to set the path of the engineering path and the Java object Source code on the Options panel.

3 Configuration Database login parameters, including the application access to the database URL, user name, password and so on.

By completing the three steps above, you can develop Java classes based on the requirements of your application. Create a new descriptor in mapping workbench (actually there is a Java Class), add attributes as needed, and automatically generate Set/get methods. Once the Java class has been developed, selecting the "Automatically map to database" option enables automatic creation of database tables. (TopLink's biggest advantage is that you can automatically generate a database's table structure after customizing Java classes).

In view of the lack of domestic toplink information, here is a brief introduction of the TopLink generated engineering document ROUTEASEMAPPINGPROJECT, the project file in the Web server startup load, can be understood as a client program access to the Database interface program, he has three types of methods:

• constructors

The main purpose is to call the Oracle.toplink.sessions.Project Adddescriptor method, which is to add the mapping relationship between the database and Java objects to project. The code model is as follows:

Public Routeasemappingproject () {
Adddescriptor (Buildaccountdescriptor ());
Adddescriptor (Buildphonedescriptor ());
.......
}
Applylogin method

It handles client login data and configures parameters for accessing the database, such as buffer pools. The code example is:

public void Applylogin () {
Configure Database access Parameters
Databaselogin login = new Databaselogin ();
Login.useplatform (New Oracle.toplink.oraclespecific.Oracle9Platform ());
Login.setdriverclassname ("Oracle.jdbc.driver.OracleDriver");  Login.setconnectionstring (Applicationconfiguration.get (CONFIGURATIONCONSTANTS.DB_CON_STR));   Login.setusername (Applicationconfiguration.get (Configurationconstants.db_user)); Login.setpassword (Applicationconfiguration.get (Configurationconstants.db_encrypted_password));
Setting Database Parameters
Login.setusesnativesequencing (TRUE);
Login.setsequencepreallocationsize (1);
Login.setshouldbindallparameters (FALSE);
Login.setshouldcacheallstatements (FALSE);
Login.setusesbytearraybinding (TRUE);
Login.setusesstringbinding (FALSE);
if (login.shouldusebytearraybinding ()) {//Can only is used with binding.
Login.setusesstreamsforbinding (FALSE);
}
Login.setshouldforcefieldnamestouppercase (FALSE);
Login.setshouldoptimizedataconversion (TRUE);
Login.setshouldtrimstrings (TRUE);
Login.setusesbatchwriting (FALSE);
if (login.shouldusebatchwriting ()) {//Can only is used with batch writing.
Login.setusesjdbcbatchwriting (TRUE);
}
Login.setusesexternalconnectionpooling (FALSE);
Login.setusesexternaltransactioncontroller (FALSE);
Setlogin (login);
}
• Establish a mapping relationship

TopLink the corresponding relationship between a Java object and a database table field by using a similar Builxxxdescriptor method, the model code is as follows:

Public descriptor Buildaccountdescriptor () {
Descriptor descriptor = new descriptor ();
Descriptor.descriptorisaggregate ();
Descriptor.setjavaclass (Com.routease.db.vo.user.Account.class);
Descriptor.setalias ("account");
Mappings.
Establish the corresponding relationship between the deposit property of the account object and the deposit field of the database table
directtofieldmapping depositmapping = new directtofieldmapping ();
Depositmapping.setattributename ("deposit");
Depositmapping.setfieldname ("deposit");
Descriptor.addmapping (depositmapping);
...
return descriptor;
}

3. Customizing background action

According to the spirit of MVC, view and model should be designed to shift the development focus to the development of the controller. The controller is the processing module which responds according to the user behavior, for example the user searches the service information through the homepage search bar, at this time, A searchtotradeentityaction (corresponding Searchtotradeentityaction.java file) in a Web service handles the action of the user. The following is a detailed analysis of this action:

Package com.routease.action.totradeentity;
Import java.util.Collection;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import Org.apache.commons.beanutils.PropertyUtils;
Import Org.apache.commons.lang.StringUtils;
Import Org.apache.struts.action.ActionForm;
Import Org.apache.struts.action.ActionForward;
Import org.apache.struts.action.ActionMapping;
Import com.routease.action.PagingAction;
Import Com.routease.action.helper.UserHelper;
Import Com.routease.db.dao.DataSource;
Import Com.routease.db.dao.totradeentity.SearchingCriteria;
Import Com.routease.db.dao.totradeentity.ToTradeEntityDAO;
Import com.routease.db.util.Constants;
Import Com.routease.db.util.Page;
public class Searchtotradeentityaction extends Pagingaction {
Public Searchtotradeentityaction ()
{
Super ();
}
The method that the Executewithdatasource method performs by default for this action
Public Actionforward Executewithdatasource (actionmapping actionmapping, Actionform actionform, HttpServletRequest Request, HttpServletResponse response, DataSource ds) throws Exception {
Accept user-submitted form data first
String objective = (string) propertyutils.getsimpleproperty (actionform, "objective");
String keyWords = (string) propertyutils.getsimpleproperty (Actionform, "keyWords");
String keywordsrange = (string) propertyutils.getsimpleproperty (Actionform, "Keywordsrange");
if (Stringutils.isempty (Keywordsrange)) {
Keywordsrange = Searchingcriteria.key_words_range_name;
}
String industryLevel1 = (string) propertyutils.getsimpleproperty (Actionform, "IndustryLevel1");
String industryLevel2 = (string) propertyutils.getsimpleproperty (Actionform, "IndustryLevel2");
String startingprice = (string) propertyutils.getsimpleproperty (Actionform, "Startingprice");
String endingprice = (string) propertyutils.getsimpleproperty (Actionform, "Endingprice");
String city = (string) propertyutils.getsimpleproperty (Actionform, "City");
String province = (string) propertyutils.getsimpleproperty (Actionform, "province");
String startnostr = (string) propertyutils.getsimpleproperty (Actionform, "Startnumber");
String lengthstr = (string) propertyutils.getsimpleproperty (actionform, "Length");
if (Stringutils.isempty (STARTNOSTR)) {
Startnostr = "1";
}
Create a query expression object SC based on the data submitted by the user
int startnumber = Integer.parseint (STARTNOSTR);
int length = Userhelper.getpaginglength (ds, request);
Totradeentitydao Servicedao = new Totradeentitydao (DS);
Searchingcriteria sc = new Searchingcriteria ();
Sc.setcity (city);
Sc.setprovince (province);
Sc.setendingprice (Endingprice);
Sc.setindustrylevel1 (INDUSTRYLEVEL1);
Sc.setindustrylevel2 (INDUSTRYLEVEL2);
Sc.setkeywords (keyWords);
Sc.setkeywordsrange (Keywordsrange);
Sc.setobjective (objective);
Sc.setstartingprice (Startingprice);
if (constants.is_test) {
System.out.println ("Start of page:" + startnumber);
}
Submit the Query Object SC and get the query result set and put its result set in the request object for easy return
Page result = Servicedao.searchtotradeentities (SC, startnumber, length);
Collection Industries = Servicedao.findindustrydistribution (SC);
Result.setsizeperpage (length);
Request.setattribute (constants.to_trade_entity, result);
Request.setattribute ("My_industries", industries);
Request.setattribute ("my_page", result);
After the business logic has been processed, return to the Success page
Return Actionmapping.findforward ("Success_page");
}
}


Searchtotradeentityaction is a typical action, from the previous note is not difficult to see, the general action is divided into three parts:

A. Accept user form data

B. Processing user form data

C. Return processing results and pages

4. Modify the page as a JSP file

Any page related to the user status should be transformed into a dynamic page (JSP file), the transformation is done on the basis of the previous static file, with the server-side returned data (stored in the Request object) to replace the static text, because this part of relatively technical not strong, so no longer detailed details.

Through the first four parts of the introduction, the basic overview of such as easy to implement the main process of implementation, in the following chapter introduces several important techniques in the Web site technology.

   the end of the article

This article mainly introduces several important techniques and ideas in the process of website implementation, and finally introduces the content of website maintenance.

I. Speed up the website

As much as possible static HTML files as the main, because the static file does not require Web server resolution and directly back to the client, so faster.

Real time on the site is not strong dynamic files can be used to refresh the background of the mechanism to periodically change to a static file or JS file, such as easy net home in the "Referral Service" column is actually the use of this mechanism, but the real-time requirements of a strong trading link is not suitable for this way.

Another way to speed up the speed of the Web site is to frequent access to the information in the database in memory, when the Web server started loading in, the idea of space change time is also worth learning.

Two Server Monitoring Management process

General Enterprise Server is the use of independent servers, the need for special maintenance, but such a high cost, it is necessary to develop a set of background monitoring procedures to the system resources, data/program backup to do monitoring, using technical means to reduce costs.

such as easy network background monitoring program to achieve the idea is: two threads, a process to monitor the server's memory, disk resources and database, Web services and other related application status, once found that there is an exception, will be the form of email or SMS to notify the system administrator; another process mainly backs up the data periodically, and uploads the backup over FTP to the specified standby server.

The System Management program plays an important role in security during the operation of the website, and it also basically does not require manual intervention, which reduces the human cost and is worthy of reference by small and medium-sized enterprises.

Three Self-help marketing platform

For enterprise E-commerce Platform, marketing is particularly important. Through different paths to collect marketing database, and regularly send users the enterprise product information, all of this process using the way of the program to achieve, convenient and easy.

Finally, a brief description of the site maintenance issues. Once the website is operated, it must ensure the 7*24 hours of its normal operation. Therefore, the maintenance of the post site is extremely important. According to the author's experience, the main need to do the following several aspects:

1. Data backup and program backup are done regularly.

2. Do a good job of Web site security protection, the important files and directories to set access rights, erecting a firewall, close the unused port. Periodically change the password of the server to prevent hacker intrusion.

3. Any program-level modifications must be validated by the test environment before they can be published to the production environment, with a set of strict publishing processes.

Do a good job of the above three aspects, the normal operation of the site can be guaranteed.

   Conclusion:

This paper focuses on the implementation of the Web site technology framework and implementation methods, and combined with an example of the application of the relevant technology. Practice has proved that this set of ideas to establish a stable and efficient website structure, has a high application value.



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.