Struts 2 Second Scenario
-
Upload
balamuruganttpl -
Category
Business
-
view
935 -
download
1
Transcript of Struts 2 Second Scenario
![Page 2: Struts 2 Second Scenario](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/2.jpg)
•User Interface
•Source File
•Memory Space
•User
Document Map
![Page 3: Struts 2 Second Scenario](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/3.jpg)
User’s scenario
First, look at this user scenario with the entrance and welcome page.
![Page 4: Struts 2 Second Scenario](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/4.jpg)
Name:
Submit
Name:
Submit
Name:
Submit
Mohammad
MohammadMohammad
![Page 5: Struts 2 Second Scenario](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/5.jpg)
Name:
Submit
Incorrect name
Name:
Submit
Incorrect name
Hamed
Correct the name& trigger the actionMohammad
Welcome
………………Hamed
![Page 6: Struts 2 Second Scenario](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/6.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/7.jpg)
ObjectName
Attr=value
Primitives
Attr=valueAttr=value
•Object
object maker
ClassNameObjectName
•Object maker
![Page 8: Struts 2 Second Scenario](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/8.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/9.jpg)
Now, let’s start it.
![Page 10: Struts 2 Second Scenario](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/10.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/11.jpg)
<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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/12.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/13.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/14.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/15.jpg)
<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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/16.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/17.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/18.jpg)
<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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/19.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/20.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/21.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/22.jpg)
<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](https://reader036.fdocuments.net/reader036/viewer/2022070317/5564c778d8b42a0a178b480f/html5/thumbnails/23.jpg)
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