![Page 2: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/2.jpg)
•User Interface
•Source File
•Memory Space
•User
Document Map
![Page 3: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/3.jpg)
User’s scenario
First, look at this user scenario with home.jsp and time.jsp pages.
![Page 4: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/4.jpg)
Time is:
Click here
Click to show time:
Click here
Click to show time:
10:10:10 pm
refresh
![Page 5: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/5.jpg)
Click the refresh link Time is: 10:10:10 pm
refresh
Time is: 10:11:11 pm
refresh
![Page 6: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/6.jpg)
How does struts work?
Now, we want to show you how struts works in the background of this scenario.
But first, you must be familiar with some primitive symbols that will helps you through this tutorial.
![Page 7: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/7.jpg)
ObjectName
Attr=value
Primitives
Attr=valueAttr=value
•Object
objectmaker
ClassNameObjectName
•Object maker
![Page 8: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/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: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/9.jpg)
Now, let’s start it.
![Page 10: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/10.jpg)
<%@ taglib prefix="s" uri="/struts-tags"%>
<a href = ”<s:url action=” ”/>”>Click here
</a>
<action name = “ ”
class = “ ”
method = “ ”>...
Find the action namefrom “home.jsp” file
2.action class=“ “ 3.action method=“ “1 2
2.action=“ “3
MyTime
currentTime
MyTime
currentTime
home.jsp
struts.xml
showTimeshowTime
Find the action class and action method from “struts.xml”
showTime
Click here
Click to show time:
![Page 11: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/11.jpg)
Value Stack
An object of action classwill be created if there is not any action object in the value stack
objectmaker
MyTime
myTime
myTime
There wasn't any action object so make a new one
1
action class=“MyTime“ action method=“currentTime“1 2
action=“showTime“3
time = null
time = null
![Page 12: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/12.jpg)
Call the action methodmyTime
MyTime.currentTime()
myTime
MyTime.currentTime()
“OK”
1 2
return value= 4
“OK”
action class=“MyTime“ action method=“currentTime“1 2
action=“showTime“3
time = “10:10:10 pm”
time = null
![Page 13: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/13.jpg)
myTime
time = “10:10:10 pm”
Value Stack
Push the action object ontop of value stack
return value=“OK”4
action class=“MyTime“ action method=“currentTime“1 2
action=“showTime“3
![Page 14: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/14.jpg)
<action name=“showTime” …> <result name = “OK”>
time.jsp </result>
.
.
.</action>
Find the target page
corresponding to return value from “struts.xml”
34
struts.xml
return value=“OK”4
action class=“MyTime“ action method=“currentTime“1 2
action=“showTime“3
Time is: ……………
refresh
<%@ taglib prefix="s" uri="/struts-tags"%>
Time is:<s:property value=” time ”/>
time.jsp
time
field=“ “5
![Page 15: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/15.jpg)
return value=“OK”4
action class=“MyTime“ action method=“currentTime“1 2
action=“showTime“3
Value Stack
Find the object from
the top of value stackto initialize the resultpage (first object that has “time” property)
entrance_o
Name = “Mohammad”
myTime
myTime
time = “10:10:10 pm”
MyTime.getTime()
myTime
time = “10:10:10 pm”
MyTime.getTime()
“10:10:10 pm”
1
Time is: ……………
refresh10:10:10 pm
field=“time“5
5
Retrieve time property from action object
![Page 16: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/16.jpg)
return value=“OK”4
action class=“MyTime“ action method=“currentTime“1 2
action=“showTime“3
Click the refresh link
Time is: 10:10:10 pm
refresh
![Page 17: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/17.jpg)
<%@ taglib prefix="s" uri="/struts-tags"%>
<a href = ”<s:url action=” ”/>”>refresh
</a>
<action name = “ ”
class = “ ”
method = “ ”>...
Find the action name
from “time.jsp” file
2.action class=“ “ 3.action method=“ “1 2
2.action=“ “3
MyTime
refresh
MyTime
refresh
time.jsp
struts.xml
refreshTimerefreshTime
Find the action class and action method from “struts.xml”
refreshTime
![Page 18: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/18.jpg)
Value Stack
New request
So, new value stack
objectmaker
MyTime
myTime
myTime
There wasn't any object so make a new one
1
action class=“MyTime“ action method=“refresh“1 2
action=“refreshTime“3
time = null
time = null
![Page 19: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/19.jpg)
Call the action methodmyTime
MyTime.refresh()
myTime
MyTime.refresh()
“OK”
1 2
return value= 4
“OK”
action class=“MyTime“ action method=“refresh“1 2
action=“refreshTime“3
time = “10:11:11 pm”
time = null
![Page 20: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/20.jpg)
myTime
time = “10:11:11 pm”
Value Stack
Push the new object
return value=“OK”4
action class=“MyTime“ action method=“refresh“1 2
action=“refreshTime“3
on top of value stack
![Page 21: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/21.jpg)
<action name=“refreshTime” …> <result name = “OK”>
time.jsp </result></action>
Find the target page
corresponding to return value from “struts.xml”
4
3
struts.xml
return value=“OK”4
action class=“MyTime“ action method=“refresh“1 2
action=“refreshTime“3
Time is: ……………
refresh
<%@ taglib prefix="s" uri="/struts-tags"%>
Time is:<s:property value=” time ”/>
time.jsp
time
Find the name’s field
field=“ “5
![Page 22: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/22.jpg)
Value Stack
Find the object from
the top of value stackto initialize the resultpage (first object that has “time” property)
entrance_o
Name = “Mohammad”
myTime
myTime
time = “10:11:11 pm”
MyTime.getTime()
myTime
time = “10:11:11 pm”
MyTime.getTime()
“10:11:11 pm”
1
return value=“OK”4
action class=“MyTime“ action method=“refresh“1 2
action=“refreshTime“3
Time is: ……………
refresh10:11:11 pm
1
field=“time“5
5
Retrieve time propertyfrom action object
![Page 23: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir](https://reader038.vdocument.in/reader038/viewer/2022103100/56649e765503460f94b77331/html5/thumbnails/23.jpg)
If there is some dark points in your mind, look at the second scenario!
If not, please report me about how much useful this document [email protected]