How does struts work? Mohammad Seyed Alavi [email protected].

23
How does struts work? Mohammad Seyed Alavi [email protected]

Transcript of How does struts work? Mohammad Seyed Alavi [email protected].

Page 1: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir.

How does struts work?

Mohammad Seyed [email protected]

Page 2: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir.

•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.

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.

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.

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.

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.

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.

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.

Now, let’s start it.

Page 10: How does struts work? Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir.

<%@ 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.

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.

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.

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.

<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.

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.

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.

<%@ 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.

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.

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.

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.

<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.

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.

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]