JPETSTORE Project Analysis - Analyze a typical J2EE application web layer implementation

xiaoxiao2021-03-06  38

About JPETSTORE (http://www.jfox.cn/jpetstore/ http://www.ibatis.com/jpetstore/JPetStore.html)

JPETSTORE is developed by Sun, which is completely rewritten based on popular pet store procedures, the earliest J2EE platform pet store network application service procedure. The most nature of other PetStore is the design similar to the Microsoft network pet store, but it is indeed a completely different network service architecture in the bones, which can be said that this architecture completely reflects the advantage of the Java program in web applications. Therefore, in it takes it as an example, the application of J2EE in the Web layer is analyzed from the underlying implementation of Java.

System architecture overview

JPETStore shows you a J2EE web layer with a simple database connection with a small pet store e-commerce platform, which integrates the elements that must be available in Web-layer applications, such as user ID authentication, product information query , Product information list, etc. In summary, JPETStore is an example of a simple and typical e-commerce that is integrated with customer shopping, order, and management.

Of course, the system in reality will not be so simple, most systems should be connected to multiple data sources and other EIS (enterprise information systems), have a more complex database system design and connection. For example, the submission of orders may be a company, credit card service may additional company, transporting is another company, in this way, the design of the data system is very complicated (generally this requires a special DBA to design.). However, as a window of a snoop J2EE, understand the operation of J2EE, JPETStore is competent.

The JPETStore is divided into multiple modules that take a loosely coupled design architecture that allows multiple data sources and EIS for information interaction. Its structure is relatively simple, including 4 parts:

· Shopping site

· Management. Such as: sales statistics, manual acceptance / reject orders

· Order processing

Accept / handle order messages through JMS

Use Java Mail to inform customers

Free order to your supplier through JMS

And modify the corresponding information of the order database

· supplier

Accept orders through JMS

Delivery goods to users

Provide a web-based inventory management

Maintenance inventory database

System architecture analysis

The website service of the pet store uses the top-down architecture, and its top layer is the jump of the WAF (Web Application Framework) Controls the application screen, and then generates the view, and then calls the business component to implement the process of the process (the overall structure is shown 1 shown).

Figure 1 JPET Store Overall Frame Structure

WAF provides services needed for many web applications, including request filtration and distribution, generating template views, reusable Taglib, and screen process control, etc.. Application components encapsulates the logic of processing, which represents commercial data, and can perform the necessary operations for these business data; entity EJB represents entities of commercial applications, including customers, addresses, accounts, etc .; session EJB provides some ways, Such as users log in, output user information, manage shopping carts, etc .; other session EJBs provide some generic methods, such as generating unique markers. The traditional JavaBean component evolves into a value object, transmitting data between EJB components and applications, successfully handling the package of each object, effectively reduces the difficulty of programming. The XML document class is used to process order information.

The WAF of this example is an effective implementation of the J2EE Blueprint Web Layer Specification. A universal web layer process can generally be divided into four steps (as shown in Figure 2):

◆ Explain a request

◆ Perform a business logic processing

◆ Select the next view

◆ Generate this view Figure 2 WAF Web layer processing

The design of the pet stores will be analyzed below, and some of the main independent components modules (shown in Figure 3):

◆ Control module is used to distribute requests to individual business processing logic, control screen jump, handling corresponding components and users

◆ Login and registration control modules are implemented and expanded by WAF

◆ Shopping cart module shopping cart tracking user shopping

◆ Login module determines the page of the user login

◆ Message module from the pet store to the order processing center for asynchronous transmission orders

◆ Category Module Provides a category view according to user query requirements

◆ Customer module represents customer information, such as address, credit card, contact information, etc.

Figure 3 JPET Store Module Design

In Figure 3, the control module will control all interaction information and execution information, each user session has a shopping cart corresponding to it.

The components of the pet store have the following parts:

◆ EJB represents the processing of commercial data and business logic

◆ The JSP page defines the framework template of the entire application view, each JSP page file consisting of templates, and various referenced graphics files.

◆ XML file is used to define screens, screen jump control, bind URL to a HTML Action, customize Signon and J2EE deployment

◆ Servlet filter is used to verify the user's secure login and output encoding

◆ Asynchronous information Send Components Transport orders to the order processing center using XML packages

◆ The installer is used to generate an example database.

Implementation of the JPETSTORE system

The previous introduction is common sense of J2EE Web architecture involved in JPETStore and some information about the JPETStore system architecture. Next, let us further understand the implementation of the JPETSTORE system.

First, come to know the JPETSTORE implementation code overall file frame (Figure 4):

Figure 4 Architecture and implementation of JPETSTORE code

The following allows us to discuss some of the techniques of the implementation. The JPETSTORE program includes Spring specifications based data sources, DAO layers, and interactive pages. You can see a sequence of beans in the XML file, which identifies: or , such as Struts-Config.xml:

Below is the three structural files of the JPETStore's Spring layer and the features implemented, as shown in Figure 5:

Presentation Layer

Interface interaction

Business Layer

Domain model implementation

Data Layer

DAO implementation

Web.xml

Struts-config.xml

DAO.XML

Figure 5 Structure of JPETSTORE SPRING

JPETSTROEDOMAIN structure (Figure 6):

Figure 6 JPETSTRORE business class

The inside is defined for some properties of some entities involved, and data package is implemented. Such as: Account.java

Public Class Account IMPLEments Serializable {

/ * Private fields * /

PRIVATE STRING UserName;

PRIVATE STRING Password;

......

/ * JavaBeans Properties * /

Public string getUsername () {

Return UserName;

}

Public void setusername (String username) {

THIS.USERNAME = UserName;

}

}

JPETSTROE PERSISTENCE is an implementation of the operation of the Domain business. Includes interfaces (IFACE) and implementation (SQLMAPDAO). Acountdao.java and Accountsqlmapdao.java

Public interface accountdao {

Public Account getAccount (String Username);

......

}

Public Class Accountsqlmapdao Extends BaseSqlmapdao Implements Accountdao {

......

Public Account getAccount (String Username) {

Return (Account) QueryForObject ("getaccountbyusername", UserName);

}

......

}

JPETSTROE Presentation defines FORMBEAN, such as AccountBean.java implements FORMBEAN for Account.java. Before performing the architecture analysis, let's take a look at the MVC architecture (Figure 6): MVC / View / Controller, MVC) architecture allows a developer to connect a visual interface to an object-oriented design, while Avoid several issues we discussed above. MVC separates the object-oriented design and visual interface by creating the following three layers:

Model: The model contains all behaviors and data required to complete the task. The model is typically composed of many classes and uses object-oriented technologies to create programs that meet five design objectives.

Interface (view): An interface is a program visual element such as dialog, menu, toolbar, and more. The interface displays the data provided from the model, which does not control data or provides other behaviors except the display. A single program or model typically has two interface behaviors. The interface displays data from the object within the model. Changes of these objects can be accomplished or not by the user's interaction. Such as: In a web browser, you must have information in the object collection and fitting stack in a web browser. You must have some way to let these objects notify the interface data has been changed. There are two ways to update the interface when the model changes.

Controller: The controller maps the model into the interface. The controller handles the user's input, and each interface has a controller. It is a set of aggregates that receive user input, create or modify the appropriate model objects and modify one state control reflected in the interface. The controller is also responsible for creating other interfaces and controllers when needed. Controllers have always decided which interfaces and model components should be active at a given moment, which has been responsible for receiving and processing user input, any variations from user input are sent from the controller to the model.

Figure 6 Foundation framework of MVC

Through the above introduction, let us analyze how JPETSTORE implements MVC and processes process. The first is the configuration of the entire system, which is implemented by some XML files. Such as:

Search for the Controller layer (in the struts folder), such as: BaseBean.java

Public Abstract Class BaseBean Extends Actionform {

......

Public void reset (ActionMapping Mapping, ServletRequest Request) {

Stmap.put ("ERRORS", ERRORLIST);

Validate ();

ErrorList = (list) RequestMap.Get ("ERRORS");

ActionerRors ActionerroS = NULL;

IF (ErrorList! = Null &&! ErrorList.isempty ()) {

ActionerRors = new actionerrors ();

ActionerRors.Add (actionerroS.Global_ERROR, NEW

ActionError ("Global.Error");

}

Return Actionerro;

}

......

}

Turn again to FormBean (in the Presentation folder), such as AccountBean.java

Public Class AccountBean Extends BaseBean {

/ * Constants * /

Private statino = accountservice.getinstance ();

......

/ * Private fields * /

PRIVATE ACCOUNT;

......

/ * Static initializer * /

STATIC {

List langlist = new arraylist ();

......

}

/ * Constructors * /

Public AccountBean () {

Account = new account ();

}

/ * JavaBeans Properties * /

Public string getUsername () {

Return Accent.getUserName ();

}

......

Public void validate () {// Error message feedback

......

}

}

The JPETSTORE is the basic technology of the MVC through the above basic techniques. summary

From Java Application to the development process of Internet development, it can be divided into three phases: the first phase is completely integrated with business logic and performance logic, using HTML, JSP, and Servlets technology development; second phase It is the development of business logic and performance logic, using HTML, JSP, Servlets, JavaBeans Compoments, and Custom Tags technology; the third phase is MVC design mode (J2EE development method). Through JPETSTORE, we have been able to fully experience the convenience, no wonder that the J2EE development method has developed, today's new technology is endless, and J2EE development technology always occupies mainstream hegemon status. .

(Diemail mailbox: cyqxyz@163.com QQ: 99676527 msn: cyqxyz@msn.com)

转载请注明原文地址:https://www.9cbs.com/read-69313.html

New Post(0)