PetStore Source Tracker (3) - Business Logic (4)

zhaozj2021-02-08  370

PetStore

Source code

(3)

- Commercial logic

(

under

)

(

Ou Xuan Xiu

)

Photo Pass, please refer to

http://www.javatwo.net/javapaper/petstore-3_business_logic.pdf

Continue

...

We have learned

Signonfilter

in

Web tier

Processing the login work, it needs to pass

EJB TIER

Compare the database read data, so it is discussed

EJB TIER

Operational situation, from the map

14

,

15

Can find the actual corresponding

EJB

It can be seen from the figure above.

EJB

The attribute is

Local stateless session bean

, This is rare, most of the books are introduced

Local bean

Usage is used

Entity Bean

This can be known

Local bean

Usage can also be used

Session bean

.

SignoneJB

Source code

PetStore_Home / SRC / Components / Signon / SRC / COM / SUN / J2EE / BluePrints / Signon / EJB / SignONEJB.JAVA

Please read the reader to add the reconnaissance program code:

public class SignOnEJB implements SessionBean {private static final String USER_HOME_ENV_NAME = "java: comp / env / ejb / local / User"; private InitialContext ic = null; private UserLocalHome ulh = null; public void ejbCreate () throws CreateException {try {ic = NEW initialContext (); //

Obtain

UserLocalHome Reference

, It is the basic information representative of users

Local Entity Bean ulh = (UserLocalHome) ic.lookup (USER_HOME_ENV_NAME);} catch (NamingException ne) {throw new EJBException ( "SignOnEJB Got naming exception!" Ne.getMessage ());}} / ** *

This function is

Signonfilter

Call, find the corresponding corresponding to the user account

User

entity

* (Instance)

, Then call

User

Entity password ratio function -

User.matchpassword () * Business method used to check if a user is allowed to sign on * / public boolean automate (string username, string password) {

//

Please join the reconnaissance program code for a later time to verify

System.out.println ("signonejb

carried out

Authenticate ()

Verify verification

userName = " userName ", password = " password); try {UserLocal user = ulh.findByPrimaryKey (userName); return user.matchPassword (password);} catch (FinderException fe) {return false; // User not found, Some of So Authentication Failed.}

...

Figure

16 signonejb

of

EJB Reference useerjb

Source code

PetStore_Home / SRC / Components / Signon / SRC / COM / SUN / J2EE / BluePrints / Signon / User / EJB / UseRejb.java

,it is

Local Entity Bean

, Corresponding database in the actual data sheet -

Userejbtable

In about

88

Can be seen

SignoneJB

The function called, please reader

On the reconnaissance program code:

Public Boolean MatchPassword (String Password) {

//

Please join the reconnaissance program code for a later time to verify

System.out.println ("useerjb

carried out

matchpassword ()

Perform a password ratio

"); Return password.equals (getpassword ());}

Figure

17 Userb

for

Entity Bean

Point selection

In one

Lower right corner

"Deployment settings"

Button, visible

18

Picture,

Select the lower left corner

"Method Implement Queries"

It

Container Methods

It

"Createrow"

I can see the picture.

18

It

SQL Query

:

Figure

18 Userb

Correspondence table

Userejbtable

The reader should be able to log in by the program code from the above list.

EJBZ Tier

Operational situation, in

Userejb

Also see a different usage, that is

Entity Bean

Using business logic -

matchpassword ()

Function, in most

EJB

Books or documents tell us that business logic should be used

Session bean

Going to practice, the information is used

Entity Bean

Come on, but the business logic compared here is very simple, only use a line of procedures to solve, so don't do it again for it.

Session bean

,

Perhaps the reader will ask why not write this function

SignoneJB

? The author believes that the password is not only used on the login process, and it may be used when the user base data edits, so still put it

Userejb

Compare:

)

We can know that the basic information of the user is existed

Userejbtable

How do we know what is the content of this information list? See note

4

.

Now repeat the first phase verification step to re-edit and deploy the program, you can find that the program is implemented as we expect!

Figure

19

Second phase program verification result

The third phase

Everyone still remember

Signonfilter

It

Validatesignon ()

Function, verification success will

Signed_on_user variable

(

The corresponding actual variable is

J_SIGNON)

Value setting true value

(TRUE)

:

HREQ.GETSESSION (). SetAttribute (Signed_On_user, New Boolean (TRUE));

When we enter the user's basic information browsing page again from the homepage, it will give

Signonfilter

Interception, from

Session

take out

Signed_on_user

variable

(

The corresponding actual variable is

J_SIGNON)

, Judging is true value

(TRUE)

,

Signonfilter

It will release the transduction to the user base information browsing screen

(Customer.do)

, Readers can refer to the following program code to add reconnaissance code, at about

125

Column

DOFILTER ()

function:

Boolean Signedon = false; if (hreq.getsession (). getAttribute (Signed_on_user)! = null) {signedon = ((boolean) hReq.getSession (). GetAttribute (Signed_on_user)). BooleanValue (); //

Add a reconnaissance code

System.out.println ("signedon =" signedon);} else {hreq.getations (). Setttribute (Signed_on_user, new boolean (false));} // jump to the resource if signed ON //

If you have already logged in, you will end this.

Filter

Work, enter

Filter chain

In this example, it is

Filter chain

Last one

Filter

So don't do anything, let the user enter his purpose picture

IF (SIGNEDON) {/////

Add a reconnaissance code

System.out.println ("

Users have logged in!

"); Chain.dofilter (request, response); return;}

Refer to the previous narrative re-deployment, execute, can obtain the following results:

Figure

20

Third phase program verification results

Customer.do

I believe that readers can be

PetStore

Logging in the flow control management has a more in-depth understanding, through the login process arrives at the user basic data browsing screen

(Customer.do)

,

* .do

Introduction to the first two

* .screen

different,

* .screen

The representative is a picture, such as

Main.screen

Representing the homepage, it can be made from multiple

.jsp

Composed;

* .do

The representative is a action,

Customer.do

Representatives related to user basic data, such as new, modified, deleted, it will pass

EJB TIER

Interaction with the database, the final result is also to be displayed,

* .screen

Mechanism constitutes a result picture, so we can imagine this

* .screen

Words,

* .do

It is a verb. In this example, just read the information, although it is used

* .do

However, there is no action, in order to let readers understand the entire architecture or here.

Please open

? Deploytool

, Click on the left pane

Files> Applications> PetStoreear> PetStorewar> MainServlet, choose the right

Alias

Page, can be found

* .do

Be

Mainservlet

Figure

21 * .do

correspond

Mainservlet

Select

General

Page can find the actual corresponding category, source code

PetStore_Home / SRC / WAF / SRC / Controller / COM / Sun / J2EE / BluePrints / Waf / Controller / Web / MainServlet.java

, About

79

The initial function can be found:

Public void init (servletconfig config) throws servletexception {//

Read the predetermined language system, the value is

"En_US" String defaultLocaleString = config.getInitParameter ( "default_locale"); defaultLocale = I18nUtil.getLocaleFromString (defaultLocaleString); this.context = config.getServletContext (); String requestMappingsURL = null; try {//

Read

. Mapping.xml requestMappingsURL = context.getResource ( "/ WEB-INF / mappings.xml") toString ();} catch (java.net.MalformedURLException ex) {System.err.println ( "MainServlet: initializing ScreenFlowManager malformed URL exception : " EX);} //

will

Mappings.xml

Turn into

Hashmap

Category and deposit

ServletContext urlMappings = URLMappingsXmlDAO.loadRequestMappings (requestMappingsURL); context.setAttribute (WebKeys.URL_MAPPINGS, urlMappings); eventMappings = URLMappingsXmlDAO.loadEventMappings (requestMappingsURL); context.setAttribute (WebKeys.EVENT_MAPPINGS, eventMappings); // ScreenFlowManager

Initialization and deposit

ServletContext getScreenflowManager (); // requestprocessor

Initialization and deposit

ServletContext getRequestProcessor ();

Figure

22 MainServlet

Actual corresponding category

Mainservlet

Read the preset language and corresponding setting files during initialization

(mapping.xml)

Initialization

ScreenflowManager

,

REQUESTPROCESSOR

, Preset language setting

Mainservlet

It

Init. Parameter

Page, value is

"EN_US"

English major)

.

Figure

23 MainServlet

It

Init. Parameter

set up

Corresponding to setting file location

PetStore_Home / src / Apps / PetStore / SRC / DOCROOT / Web-INF / MAPPINGS.XML

We can

95

Find

Customer.do

Related settings

com.sun.j2ee.blueprints.PetStore.Controller.Web.Actions.customerhtmLAction

This paragraph

(tag)

There are three parameters:

URL:

Mark the corresponding action

Web-action-class:

Actual implementation category

Screen:

Result display screen

* .do

The operation mechanism is

Servlet

received

REQUEST

,From

Mappings.xml

Found

URL

,

REQUESTPROCESSOR

According to

Web-action-class

Initialization and execution,

ScreenflowManager

Pass the execution result back

* .screen

, Use the first two of this series to introduce

* .screen

The mechanism constitutes the actual picture, responds to the user, the rough process is the case, it is actually more complicated, due to involving

Web tier

versus

EJB TIER

Communication, but in this case,

REQUESTPROCESSOR

correspond

Web-action-class (customerhtmlaction)

Didn't do anything, follow-up

REQUESTPROCESSOR

Receive result display screen

Customer.Screen

That is converted

(Forward)

action.

Mappings.xml

After reading

Hashmap

Category deposit

ServletContext

For all access

PetStore

The system of the system is used, then

ScreenflowManager

and

REQUESTPROCESSOR

initial

Chemical

ServletContext

.

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

New Post(0)