+ All Categories
Home > Business > Struts 2 Second Scenario

Struts 2 Second Scenario

Date post: 27-May-2015
Category:
Upload: balamuruganttpl
View: 928 times
Download: 1 times
Share this document with a friend
Popular Tags:
23
How does struts work? Mohammad Seyed Alavi [email protected]
Transcript
Page 1: Struts 2 Second Scenario

How does struts work?

Mohammad Seyed [email protected]

Page 2: Struts 2 Second Scenario

•User Interface

•Source File

•Memory Space

•User

Document Map

Page 3: Struts 2 Second Scenario

User’s scenario

First, look at this user scenario with the entrance and welcome page.

Page 4: Struts 2 Second Scenario

Name:

Submit

Name:

Submit

Name:

Submit

Mohammad

MohammadMohammad

Page 5: Struts 2 Second Scenario

Name:

Submit

Incorrect name

Name:

Submit

Incorrect name

Hamed

Correct the name& trigger the actionMohammad

Welcome

………………Hamed

Page 6: Struts 2 Second Scenario

How does struts work?

Now, we want to show you how struts works in the background of this user scenario.

But first, you must be familiar with some primitive symbols that will help you through this tutorial.

Page 7: Struts 2 Second Scenario

ObjectName

Attr=value

Primitives

Attr=valueAttr=value

•Object

object maker

ClassNameObjectName

•Object maker

Page 8: Struts 2 Second Scenario

Primitives (cont.)

ObjectName

Attr=value

Class.Method(args)

Return value

•Method return

ObjectName

Attr=value

Class.Method(args)

•Method call

Page 9: Struts 2 Second Scenario

Now, let’s start it.

Page 10: Struts 2 Second Scenario

Name:

Submit

Name:

Submit

Name:

Submit

Mohammad

Mohammad

name =“ ”

Mohammad

1

<%@ taglib prefix="s" uri="/struts-tags"%>

<s:textfield name=” name ”...

entrance.jspFind the nam

e’s fieldname

2 field=“ ”

Page 11: Struts 2 Second Scenario

<s:form action = “ ” . . .

<action name = “ ”

class = “ ”

method = “ ”>...

Find the action name

from “entrance.jsp” file

1.name=“Mohammad” 2.action class=“ “

3.action method=“ “

1 3

52.action=“ “4

submit

Entrance

signIn

submit

Entrance

signIn

entrance.jsp

struts.xml

submit

1.field=“name”2

Page 12: Struts 2 Second Scenario

Value Stack

An object of action classwill be created if there is not any of that in value stack

objectmaker

Entrance

entrance

entrance

name = “Mohammad”

There wasn't any object so make new one

entrance_o

Name = “Mohammad”

entrance

Entrance.setName(“Mohammad”)

entrance

name = “Mohammad”

Entrance.setName(“Mohammad”)

void

call the setter

name=“Mohammad” action class=“Entrance“

3.action method=“signIn“

1 3

52.action=“submit“4

3

12

field=“name”2

3

Page 13: Struts 2 Second Scenario

Call the action methodentrance

name = “Mohammad”

Entrance.signIn()

entrance

name = “Mohammad”

Entrance.signIn()

“No”

name=“Mohammad” action class=“Entrance“

action method=“signIn“

1 3

52.action=“submit“4

3 5

return value= 6

“No”

field=“name”2

Page 14: Struts 2 Second Scenario

entrance

name = “Mohammad”

Value Stack

Push the object on top ofvalue stack

name=“Mohammad” action class=“Entrance“

action method=“signIn“

1 3

52.action=“submit“4 return value=“No”6

field=“name”2

Page 15: Struts 2 Second Scenario

<action name=“submit”> <result name = “No”>

main.jsp?msg = “Incorrect name” </result>

.

.

.</action>

Find the target page

corresponding to return value from “struts.xml”

Name:

Submit

Incorrect name

name=“Mohammad” action class=“Entrance“ action method=“signIn“1 2 3

action=“submit“4 return value=“No”5

4

5

struts.xml

field=“ ”6

<%@ taglib prefix="s" uri="/struts-tags"%>

Name:<s:textfield name=” name ”...

entrance.jsp

Find the name’s field

name

Page 16: Struts 2 Second Scenario

Value Stack

Find the object from

the top of value stackto initialize the resultpage (first object that has “name” property)

entrance_o

Name = “Mohammad”

entrance

entrance

name = “Mohammad”

Entrance.getName()

entrance

name = “Mohammad”

Entrance.getName()

“Mohammad”

Name:

Submit

Incorrect name

Mohammad

Name:

Submit

Incorrect name

HamedCorrect the nam

e

& trigger the action

name=“ ”

action class=“Entrance“ action method=“signIn“

5

2 3

action=“submit“4

Hamed

2 1

field=“name”1

Retrieve name propertyfrom action object

Page 17: Struts 2 Second Scenario

1.name=“Hamed”1 field=“ ”2

<%@ taglib prefix="s" uri="/struts-tags"%>

Name:<s:textfield name=” name ”...

entrance.jsp

name

Find the name’s field

Page 18: Struts 2 Second Scenario

<s:form action = “ ” . . .

<action name = “ ”

class = “ ”

method = “ ”>...

Find the action name

from “entrance.jsp” file

1.name=“Hamed” 2.action class=“ “

3.action method=“ “

1 3

52.action=“ “4

submit

Entrance

signIn

submit

Entrance

signIn

entrance.jsp

struts.xml

submit

field=“name”2

Page 19: Struts 2 Second Scenario

Value Stack

New Request

So, new value stack

objectmaker

Entrance

entrance

entrance

name = “Hamed”

There wasn't any object so make new one

entrance_o

Name = “Mohammad”

entrance

Entrance.setName(“Hamed”)

entrance

name = “Hamed”

Entrance.setName(“Hamed”)

void

call the setter

name=“Hamed” action class=“Entrance“

3.action method=“signIn“

1 3

52.action=“submit“4

3

12

field=“name”2

3

Page 20: Struts 2 Second Scenario

Call the action methodentrance

name = “Hamed”

Entrance.signIn()

entrance

name = “Hamed”

Entrance.signIn()

“Yes”

1.name=“Hamed” action class=“Entrance“

action method=“signIn“

1 3

5 action=“submit“4 return value= 6

“Yes”

3 5

field=“name”2

Page 21: Struts 2 Second Scenario

entrance

name = “Hamed”

Value Stack

Push the new object

name=“Hamed” action class=“Entrance“

action method=“signIn“

1 3

5 action=“submit“4 return value=“Yes”6

on top of value stack

field=“name”2

Page 22: Struts 2 Second Scenario

<action name=“submit”> <result name = “No”> … </result> <result name = “Yes”>

welcome.jsp </result></action>

Find the target page

corresponding to return value from “struts.xml”

Welcome

………………

5

name=“Hamed” action class=“Entrance“ action method=“signIn“1 2 3

action=“submit“4 return value=“Yes”5

4

struts.xml

<%@ taglib prefix="s" uri="/struts-tags"%>

Welcome<s:property value=” name ”...

welcome.jsp

name

field=“ ”6

Page 23: Struts 2 Second Scenario

Value Stack

Find the object from

the top of value stackto initialize the resultpage (first object that has “name” property)

entrance_o

Name = “Mohammad”

entrance

entrance

name = “Hamed”

Entrance.getName()

entrance

name = “Hamed”

Entrance.getName()

“Hamed”

Welcome

………………Hamed

1.name=“Hamed” action class=“Entrance“ action method=“signIn“1 2 3

action=“submit“4

2

field=“name”5

5

Retrieve name property from action object


Recommended