1 / 23

How does struts work?

How does struts work?. Mohammad Seyed Alavi m.s.alavi@ece.ut.ac.ir. Document Map. User Interface. Source File. Memory Space. User. User’s scenario. First, look at this user scenario with home.jsp and time.jsp pages. Click to show time:. Click here. Click the link. Click to show time:.

chung
Download Presentation

How does struts work?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Document Map • User Interface • Source File • Memory Space • User

  3. User’s scenario • First, look at this user scenario with home.jsp and time.jsp pages.

  4. Click to show time: Click here Click the link Click to show time: Click here Time is: 10:10:10 pm refresh

  5. Click the refresh link Time is: 10:10:10 pm refresh Time is: 10:11:11 pm refresh

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

  7. Primitives ObjectName Attr=value • Object Attr=value Attr=value ClassName ObjectName • Object maker object maker

  8. Primitives (cont.) Class.Method(args) ObjectName Attr=value • Method call Class.Method(args) ObjectName Attr=value • Method return Return value

  9. Now, let’s start it.

  10. 2.action class=“ “ 3.action method=“ “ 1 2 2.action=“ “ 3 home.jsp <%@ taglib prefix="s" uri="/struts-tags"%> <a href = ”<s:url action=” ”/>”> Click here </a> Find the action name from “home.jsp” file showTime showTime showTime Click to show time: Find the action class and action method from “struts.xml” Click here struts.xml <action name = “ ” class = “ ” method = “ ”> . . . MyTime MyTime currentTime currentTime

  11. action class=“MyTime“ action method=“currentTime“ 1 2 action=“showTime“ 3 An object of action class will be created if there is not any action object in the value stack There wasn't any action object so make a new one Value Stack MyTime 1 myTime object maker time = null myTime time = null

  12. action class=“MyTime“ action method=“currentTime“ 1 2 action=“showTime“ return value= 3 4 MyTime.currentTime() 1 2 Call the action method myTime time = null Return the return value MyTime.currentTime() myTime time = “10:10:10 pm” “OK” “OK”

  13. action class=“MyTime“ action method=“currentTime“ 1 2 action=“showTime“ return value=“OK” 3 4 Push the action object on top of value stack myTime time = “10:10:10 pm” Value Stack

  14. action class=“MyTime“ action method=“currentTime“ 1 2 action=“showTime“ return value=“OK” field=“ “ 3 4 5 struts.xml <action name=“showTime” …> <result name = “OK”> time.jsp </result> . . . </action> 3 4 Find the target page corresponding to return value from “struts.xml” time.jsp <%@ taglib prefix="s" uri="/struts-tags"%> Time is: <s:property value=” time ”/> Go to the result page time Time is: …………… refresh

  15. action class=“MyTime“ action method=“currentTime“ 1 2 action=“showTime“ return value=“OK” field=“time“ 3 4 5 Retrieve time property from action object Find the object from the top of value stack to initialize the result page (first object that has “time” property) MyTime.getTime() myTime Value Stack 1 5 myTime time = “10:10:10 pm” MyTime.getTime() Time is: …………… myTime refresh entrance_o 10:10:10 pm time = “10:10:10 pm” “10:10:10 pm” Name = “Mohammad”

  16. action class=“MyTime“ action method=“currentTime“ 1 2 action=“showTime“ return value=“OK” 3 4 Click the refresh link Time is: 10:10:10 pm refresh

  17. 2.action class=“ “ 3.action method=“ “ 1 2 2.action=“ “ 3 time.jsp <%@ taglib prefix="s" uri="/struts-tags"%> <a href = ”<s:url action=” ”/>”> refresh </a> Find the action name refreshTime refreshTime refreshTime from “time.jsp” file Find the action class and action method from “struts.xml” struts.xml <action name = “ ” class = “ ” method = “ ”> . . . MyTime MyTime refresh refresh

  18. action class=“MyTime“ action method=“refresh“ 1 2 action=“refreshTime“ 3 New request So, new value stack There wasn't any object so make a new one Value Stack MyTime 1 myTime object maker time = null myTime time = null

  19. action class=“MyTime“ action method=“refresh“ 1 2 action=“refreshTime“ return value= 3 4 MyTime.refresh() 1 2 Call the action method myTime time = null Return the return value MyTime.refresh() myTime time = “10:11:11 pm” “OK” “OK”

  20. action class=“MyTime“ action method=“refresh“ 1 2 action=“refreshTime“ return value=“OK” 3 4 Push the new object on top of value stack myTime time = “10:11:11 pm” Value Stack

  21. action class=“MyTime“ action method=“refresh“ 1 2 action=“refreshTime“ return value=“OK” field=“ “ 3 4 5 struts.xml <action name=“refreshTime” …> <result name = “OK”> time.jsp </result> </action> 3 Find the target page 4 corresponding to return value from “struts.xml” time.jsp <%@ taglib prefix="s" uri="/struts-tags"%> Time is: <s:property value=” time ”/> Find the name’s field Go to the result page time Time is: …………… refresh

  22. action class=“MyTime“ action method=“refresh“ 1 2 action=“refreshTime“ return value=“OK” field=“time“ 3 4 5 Retrieve time property from action object Find the object from the top of value stack to initialize the result page (first object that has “time” property) MyTime.getTime() myTime 1 Value Stack 1 5 myTime time = “10:11:11 pm” MyTime.getTime() Time is: …………… myTime refresh entrance_o 10:11:11 pm time = “10:11:11 pm” “10:11:11 pm” Name = “Mohammad”

  23. 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 is. m.s.alavi@ece.ut.ac.ir

More Related