Establish, package, deploy, and run Duke Bank Application

xiaoxiao2021-03-05  30

Establish, package, deploy, and run Duke Bank Application

Author: Jimsons

table of Contents

Preparation ...

2. Start the server ...

2.1 Create Bank Database ...

2.2 Capture Database Mode ...

2.3 Creating a JDBC data source ...

2.4 Add users and groups to the File Domain ...

3. Compile DUKE Bank Application Code ...

4. Package and deploy Duke Bank Application ...

4.1 Package Enterprise Beans.

4.2 Packaging Applications Client ...

4.3 Packaging the web client ...

4.4 Packaging and deploying applications ...

5. Run Applicate Client Application CLIENT

6. Run the web client ...

7. About the error correction in the source code ...

7.1 Errors in NextIDBean Codes ...

7.2 Errors in the web module ...

8. Reference information ...

Preparation

Suppose you have installed J2EE 1.4 SDK in your computer, you must go before the Duke Bank application is created.

http://java.sun.com/j2ee/1.4/download.html #tutorial Download J2ETORIAL Complicated Pack and Unpacking it, assumes that the path you decompress is

/ j2eetutorial14, an open example profile

/j2eetutorial14/examples/common/build.properties

l Set the value of J2EE.HOME to your application server (Application Server) installation location, for example your application server is installed in C: / Sun / Appserver, then you should set the following: J2EE.HOME = C: / sun / Appserver

l Set the value of J2EE.TUTORIAL.HOME to your J2EETORIAL installation location, for example: J2EE.TUTORIAL.HOME = C: / J2Eetutorial14

l If you install the application server, the administrator's username is not using the default admin, then you have to change the value of admin.uses to your username.

l If you install an application server, you don't use the default 8080 port, you have to change the value of Domain.Resources.port to your port.

l Sets the value of the "the value of as_admin_password in the /j2eetututial14/examples/common/admin-password.txt file to the administrator password you set when you install the application server, such as as_admin_password = YourPassword

2. Start the server

You must first start the PointBase database server and add information about the customer and account to the database, you have to add some resources to the application server, and finally you can start packaging, deploying, and operating examples.

2.1 Creating a Bank Database

You must first create a database and enter data to the data table, then enterprise beans to read or write data from it, follow these steps to create a data table and enter the data:

1. Start the PointBase database server

2. Open the command line, go to / j2eetututorial14 / example, execute command asant create-db_common, this command calls the PointBase Terminal Tool Library to perform / j2eetutorial14 / examples / bank / sql / crete -table.sql's SQL statement, the functionality of these SQL statements is to remove all existing tables and create a new table and insert data into the table, because these tables do not exist for the first time these statements, so you will See some SQL error messages, you can ignore these error messages.

2.2 Capture Database Mode

After creating a table and entering the data, you can capture the structure of the table and save it into a mode file, capture the mode by following the steps:

1. Open the command line and switch to / j2eetututorial14 / example / bank / directory 2. Perform the following command asant capture-db-schement, generate mode files after this command / j2eetututorial14 / examples / Bank / Build / Dukesbank.dbschema

2.3 Creating a JDBC Data Source

Duke Bank's enterprise bean uses JNDi Name JDBC / BankDB to reference the database, follow these steps:

1. Open the management terminal page

Http: // localhost: 4848 / asadmin

2. Expand the JDBC branch, select JDBC Resources, select New

3. Name it as jdbc / bandb and map it to PointBasePool

2.4 Add users and groups to the File domain

After adding users and groups to the FILE security domain, the application server can determine which users can access the web client's enterprise bean methods and resources, the steps added are as follows:

1. Open the management terminal page

Http: // localhost: 4848 / asadmin

2. Expand the Configuration branch and expand the Security branch

3. Expand the Realms branch and select the File domain

4. Click Manage Users and click New

5. Enter the user and group of Duke Bank according to the following table

User

Password

Group

200

J2EE

BankcuStomer

Bankadmin

J2EE

Bankadmin

3. Compile DUKE Bank Application Code

Open the command line, go to the / j2eetutorial14 / example / group, execute the command asant building, this command compiles all the code of the enterprise bean, the application client, and the web client, and the compiled code is located in / J2EETORIAL14 / EXAMPLES / BANK / BUILD directory.

4. Package and deploy DUKE Bank Application

The following process assumes that you are more familiar with the process of packaged enterprise beans, application client, and web applications with deployment tools. Here is how to pack and deploy Duke Bank (if you do this, deploy or run this application) There is also a problem, then you can use our EAR files that are available in the / j2eetututorial14 / examples / bank / provided-jars / directory to deploy and run this example)

4.1 Package Enterprise Beans

1. Create an EJB JAR module and name DukeSbankejbjar, save it to / j2eetutositial14 / examples / bank / directory.

2. Add / j2eetutorial14 / example / bank / build / com / sun / ebank / directory EJB and UTIL package, there is a dukesbank.dbschema file in / j2eetutorial14 / examples / bank / build / directory .

3. Create an entity beans (select Add to DukesBankejbjar)

a. Create the CMP2.0 (container management persistence) enterprise bean in each table below with the Enterprise Bean Wizard:

Accountbean

The settings are as follows

:

Setting

Value

Local Home Interface

Localaccouneome

Local Interface

Localaccount

Persistent Fields

Accountid, Balance, Beginbalance, BeginbalancetimeStamp, Creditline, Description, Type

Abstract Schema Name

Accountbean

PRIMARY Key Class

EXISTING FIELD Accountid

Customerbean

The settings are as follows

:

Setting

Value

Local Home Interface

Localcustomerhome

Local Interface

LocalCustomer

Persistent Fields

City, Customerid, Email, Firstname, Lastname, MiddleInitial, Phone, State, Street, ZIP

Abstract Schema Name

Customerbean

PRIMARY Key Class

EXISTING FIELD CUSTOMERID

TXBean

The settings are as follows

:

Setting

Value

Local Home Interface

Localtxhome

Local Interface

Localtx

Persistent Fields

Amount, Balance, Description, TimeStamp, TXID

Abstract Schema Name

TXBean

PRIMARY Key Class

EXISTING FIELD TXID

Nextidbean

The settings are as follows

:

Setting

Value

Local Home Interface

LocalNextidHome

Local Interface

LocalNextid

Persistent Fields

Beanname, ID

Abstract Schema Name

Nextidbean

PRIMARY Key Class

EXISTING FIELD BEANNAME

4. Establish an entity bean according to the table below:

Multi-Plicity

Bean a

FIELD REFERENCING Bean B And Field Type

Bean B

Field Referencing Bean A and Field Type

*: *

Accountbean

Customers, java.util.collection

Customerbean

Accounts, Java.util.

COLLECTION

1:*

Accountbean

None

TXBean

Account

b. In the Sun-Specific Settingsàcmp Database dialog

1. Name the JNDI name JDBC / BankDB

2. Click Create Database Mappings to select Map To Tables in Database Schema File and select Dukesbank.dbschema from the drop-down list, as shown below.

3. Each time you select a business bean, you will display a map of your persistent domain, please confirm those domains and relationships.

c. Set the EJB QL query statement according to the following table as Finder

Duke

Finder in the bank

Inquire

Enterprise

Bean

Method

EJB QL Query

Accountbean

Findbycustomerid

Select Distinct Object (a)

From AccountBean a, in (a.customers) AS C

Where c.customerid =? 1

Customerbean

Findbyaccountid

Select Distinct Object (c)

From Customerbean C, In (C.accounts) AS A

WHERE A.accountId =? 1

Customerbean

Findbylastname

Select Object (c)

From Customerbean C

Where c.lastname =? 1TXBean

Findbyaccountid

Select Object (T)

From txbean t

WHERE T.account.accountid =? 3

AND (t.timestamp> =? 1 and t.timestamp <=? 2)

d. In the nextidbean's Transaction tab, set the Transaction Attributes property of the nextidBean.getNextid method to Requires New.

5. Call the Enterprise Bean Wizard Create Stateful Session Beans in the following table (ie state session bean)

Session bean

Home interface

Remote Interface

Implementation class

Account

Controllerbean

Account

Controllerhome

Account

CONTROLLER

AccountControllerbean

Customer

Controllerbean

Customer

Controllerhome

Customer

CONTROLLER

CustomerControllerbean

TxControllerbean

TxControllerhome

TxController

TXBean

a. Adding session beans to Local Entity Beans, based on the EJB References of Local Entity Beans.

EJB REFERENCES in AccountControllerbean

Coded name

EJB TYPE

Interfaces

Home interface

Local Interface

Enterprise

Bean name

EJB / Account

Entity

Local

Local

AccountHome

Localaccount

Accountbean

EJB /

Customer

Entity

Local

Local

Customerhome

LocalCustomer

Customerbean

EJB / NEXTID

Entity

Local

Local

NextiDHome

LocalNextid

Nextidbean

EJB REFERENCES in CustomerControllerbean

Coded name

EJB TYPE

Interfaces

Home interface

Local Interface

Enterprise

Bean name

EJB / CUSTOMER

Entity

Local

Local Customerhome

Local

Customer

Customerbean

EJB / NEXTID

Entity

Local

Local

NextiDHome

Local

NextID

Nextidbean

EJB References in TXControllerbean

Coded name

EJB TYPE

Interfaces

Home interface

Local Interface

Enterprise

Bean name

EJB / Account

Entity

Local

Local

AccountHome

Local

Account

Accountbean

EJB /

TX

Entity

Local

Local

Txhome

Localtx

TXBean

EJB / NEXTID

Entity

Local

Local

NextiDHome

Local

NextID

Nextidbean

b. Set the Transaction Management of all session beans to Container-Managed, Container Management 6. Save this module

4.2 Packaging Applications Client

Call Application Client Wizard

a. Create an application client module, name it dukesbankacjar and save it to / j2eetutorial14 / examples / bank / directory

b. Add / j2eetutorial14 / example / bank / build / com / sun / eBank / directory AppClient, Util, EJB / Exception Package and EJB / * / * Controller *, HOME and remote interface files (ie AccountController, AccountControllerHome, CustomerController, CustomerControllerHome, TXController, TXControllerHome to JAR.

c. Select AppClient.bankadmin as the application client's Main Class (main class)

2. Add to add EJB reference to session beans according to the table below

Coded name

EJB TYPE

Interface

JNDI Name of Session Bean

EJB / ACCOUNTCONTROLLER

Session

REMOTE

AccountControllerbean

EJB / CUSTOMERCONTROLLER

Session

REMOTE

CustomerControllerbean

3. Save this module.

4.3 Packaging the web client

1. Create a web module through the Web Component Wizard, named DukeSbankwar and saved to / j2eetutositial14 / examples / bank / directory, select Dispatcher as a servlet class, others remain default.

2. Add the following to the web module

a. Add / J2Eetutorial14 / Examples / Bank / Build / COM / Sun / EBANK / Directory Web, Util, EJB / Exception Package and EJB / * / * Controller * ie Home and Remote Interface files (ie AccountController, AccountControllerHome, CustomerController, CustomerControllerHome, TXController, TXControllerHome are in the module.

b. Add / J2Eetutorial14 / Examples / Bank / Build / Directory, all JSP pages, all webmedages * .properties files and tutorial-template.tld files into the module.

c. Drag the WebMessages * .properties file from the root directory to the web-inf / class directory in the dialog box to add files, as shown below

3. Set the context root to / Bank

4. Open the Aliases tab of Dispatcher Components, Add / AccountHist, / AccountList, / ATM, / Atmack, / Main, / Transferack, / TransferFunds, And / Logoff as Aliases

5. Add the session bean listed in the table below to EJB reference

Coded name

EJB TYPE

Interface

JNDI Name of Session Bean

EJB / ACCOUNTCONTROLLER

Session

RemoteaccountControllerbean

EJB / CUSTOMERCONTROLLER

Session

REMOTE

CustomerControllerbean

EJB / TXCONTROLLER

Session

REMOTE

TxControllerbean

6. Add a group called Bank in the label JSP Property, this group corresponds to the URL Pattern (URL Mode) to * .jsp, add /Template/prelude.jspf to include Preelude

7. At the Context tag, add the parameters named javax.servlet.jsp.jstl.fmt.localizationContext, the value is WebMessages.

8. Adding security controls on the Security tag

a. Select Form Based as a User Authentication method, set the value of Realm to File in Authentication Settings, login page Set to /logon.jsp, Error Page Set to /logonerror.jsp.

b. Add a Security Constraint and Web Resource Collection, with the default name provided by deploytool

c. Add URL Patterns (URL Mode) in Web Resource Collection: / Main, / AccountList, / AccountHist, / ATM, / Atmack, / TransferFunds, and / Transferack

d. Select the HTTP method POST and GET.

e. Add security role (Authorized role) BankcuStomer

9. Save this module

4.4 Packing and deploying an app

1. Create a J2EE Application (J2EE application), name it dukesbankapp, save it to / j2eetutorial14 / example / bank / directory

2. Add

Dukesbankacjar

Application Client Module to DukesbankApp

3.

Add dukesbankejbjar, ready-to-EJB module to DukesbankApp

4.

Add dukesbankwar, Web module to DukesbankApp

5.

Adding a security role (Security Roles) name

Bankadmin and

BankcuStomer

6.

Add the following security settings to enterprise beans (Security Settings)

a.

AccountControllerBean:

In the Security tag, RemoveCustomerfromaccount,

Removeaccount,

CreateAccount, and

AddCustomertoaccount

The security role of the restricted access is BankAdmin; in the General tab, click Sun-Specific Settings, and then click IOR in the pop-up dialog box, set the Required to true, set realm to file.

b.

CustomerControllerBean:

In the security tag, the method will be GetCustomersofaccount,

CreateCustomer,

GetCustomersoflastName,

SetName,

RemoveCustomer, and

SetAddress

The security role of the restricted access is BankAdmin; in the General tab, click Sun-Specific Settings, and then click IOR in the pop-up dialog box, set the Required to true, set realm to file.

C.

TxControllerbean

: On the Security tag, will get the method gettxsofaccount,

Makecharge,

Deposit,

Transferfunds,

Withdraw, and

Makepayment

Safety role of restriction access to BankCuStomer

7.

If you haven't launched the application server (Application Server.) Then start it now.

8. Map BankCustomer roles to the BankcuStomer group

9. Map BankAdmin roles to BankAdmin group

10. Save this application module

11. DEPLOY (deploy) application, in deployment

KesbankApp

The dialog box is selected Return Client JAR to return to the client JAR option.

12. Select Server in Deploytool, select the BANK appearing on the right and start it.

5. Run Applicate Client Application CLIENT

Please run the application client according to the following steps:

1. Open the command line, go to

/ J2Eetutorial14 / Examples / Bank / Directory

2. If you want to run an English version of the client, enter the following command: AppClient -client dukesbankappclient.jar

Dukesbankappclient.jar

This file is the file you return to the client JAR when you just deploy.

3.

If you want to run Spanish version of the client, run the following command: AppClient -client dukesbankappclient.jar ES

4.

In the pop-up login box, enter the username BankAdmin password to j2ee, then you can see the following interface.

6. Run the web client

Please run the web client according to the following steps

1. Open the address in your browser

Http: // localhost: 8080 / bank / main,

If you look at the Spanish version of the client, simply change in the browser language setting.

2.

In the login page, enter the username 200, password J2EE and submit it.

3.

When you choose Account List, you will see the following screen.

7. About the error correction in the source code

7.1 Errors in NextIDBean Codes

This error will cause an error that will not be completed, open the nextidBean.java file under / j2eetututorial14 / examples / bank / src / com / su / ebank / ejb / util / directory, find the following line code

Public Object Ejbcreate () throws createException {

Change the return type of method ejbcreate () by Object to String, recompile, and update this file in DeployTool, re-deploy it.

7.2 Errors in the web module

Open the web client, enter the username password and then submit the javax.servlet.jsp.jsptagexception error, please correct the following steps:

1. New Java documentation with text editor is named Customerhackfilter, save it

/ J2Eetutorial14 / Examples / Bank / SRC / COM / SUN / EBANK / WEB

In the directory, the content is as follows:

Package com.sun.ebank.Web;

Import javax.servlet. *;

Import javax.servlet.http. *;

Import com.sun.ebank.util.debug;

Import com.sun.ebank.web. *;

Import java.io.ioException;

/ **

* this is a dumb Hack. Update 4 Seems to Broken Unless A * Customerbean Is Placesd in The Request Linked to The BeanManager.

* Naturally, we need to add a beanmanager to the session here,

* Doing some of the work the dispatcher sheap.

* /

Public Class Customerhackfilter Implements Filter

{

Private filterconfig filterfig = null;

Public void init (FilterConfig filterConfig)

Throws servletexception

{

THIS.FILTERCONFIG = FilterConfig;

}

Public void destroy () {

THIS.FILTERCONFIG = NULL;

}

Public Void Dofilter (ServletRequest Req, ServletResponse Response,

FILTERCHAIN ​​chain

Throws oException,

ServletException

{

HTTPSERVLETREQUEST REQEST = (httpservletRequest) Req;

HttpSession session = request.getations ();

Beanmanager beanufacture =

(BeanManager) Session.getaTRibute ("BeanManager");

IF (beanManager == null) {

Debug.print ("Hack - Creating Bean Manager.");

Beanmanager = new beanmanager ();

Session.setttribute ("BeanManager", BeanManager;

}

Customerbean Customerbean = New Customerbean ();

CustomerBean.setBeanMAGER (BeanManager);

Request.setttribute ("Customerbean", Customerbean;

Debug.print ("Hack - Added Customerbean to Request");

Chain.dofilter (Request, Response);

}

}

2. Re-build source code

3. Select the dukesbankwar module, edit the content, find COM / Sun / EBANK / Web / CustomerhackFilter.class, add it to the package.

4. Select the DukesBankwar module, click Edit Filter List, click Add Filter in the pop-up dialog box, select com.sun.ebank.Web.customerhackfilter, filter name for Customerhack in Filter Class drop-down list, select OK

5. Still in this label, click Add, pop up "Add servlet filter mapping", select CustomerHack in the Filter Name drop-down list, select "Filter this servlet", select OK, as shown below.

6. Save this module and re-deploy it to fix an error

8. Reference

[1].

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html/[2].

Http://docs.jboss.org/jbossas/getting_started/startguide40/

[3]. Flying Technology Product R & D Center. JSP application development detailed. Electronic Industry Press. 2004.5

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

New Post(0)