Struts 2 Second Scenario

1,253 views
1,147 views

Published on

Published in: Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,253
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
49
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Struts 2 Second Scenario

  1. 1. How does struts work? Mohammad Seyed Alavi [email_address]
  2. 2. <ul><li>User Interface </li></ul><ul><li>Source File </li></ul><ul><li>Memory Space </li></ul><ul><li>User </li></ul>Document Map
  3. 3. User’s scenario <ul><li>First, look at this user scenario with the entrance and welcome page. </li></ul>
  4. 4. Name: Submit Name: Submit Name: Submit Mohammad Mohammad Fill Form's Field Trigger the action Mohammad
  5. 5. Name: Submit Incorrect name Name: Submit Incorrect name Hamed Correct the name & trigger the action Mohammad Welcome ……………… Hamed
  6. 6. How does struts work? <ul><li>Now, we want to show you how struts works in the background of this user scenario. </li></ul><ul><li>But first, you must be familiar with some primitive symbols that will help you through this tutorial. </li></ul>
  7. 7. Primitives ObjectName Attr=value Attr=value Attr=value <ul><li>Object </li></ul>object maker ClassName ObjectName <ul><li>Object maker </li></ul>
  8. 8. Primitives (cont.) ObjectName Attr=value Class.Method(args) Return value <ul><li>Method return </li></ul>ObjectName Attr=value Class.Method(args) <ul><li>Method call </li></ul>
  9. 9. <ul><li>Now, let’s start it. </li></ul>
  10. 10. Name: Submit Name: Submit Name: Submit Mohammad Mohammad Fill Form's Field Trigger the action name =“ ” Mohammad 1 <%@ taglib prefix=&quot;s&quot; uri=&quot;/struts-tags&quot;%> <s:textfield name=” name ”... entrance.jsp Find the name’s field name 2 field=“ ”
  11. 11. <s:form action = “ ” . . . <action name = “ ” class = “ ” method = “ ”> . . . Find the action name from “entrance.jsp” file Find the action class and method from &quot;struts.xml&quot; 1.name=“Mohammad” 2.action class=“ “ 3.action method=“ “ 1 3 5 2.action=“ “ 4 submit Entrance signIn submit Entrance signIn entrance.jsp struts.xml submit 1.field=“name” 2
  12. 12. Value Stack An object of action class will be created if there is not any of that in value stack object maker 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 5 2.action=“submit“ 4 3 1 2 field=“name” 2 3
  13. 13. Call the action method Return the return value entrance name = “ Mohammad” Entrance.signIn() entrance name = “ Mohammad” Entrance.signIn() “ No” name=“Mohammad” action class=“Entrance“ action method=“signIn“ 1 3 5 2.action=“submit“ 4 3 5 return value= 6 “ No” field=“name” 2
  14. 14. entrance name = “ Mohammad” Value Stack Push the object on top of value stack name=“Mohammad” action class=“Entrance“ action method=“signIn“ 1 3 5 2.action=“submit“ 4 return value=“No” 6 field=“name” 2
  15. 15. <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 Go to the result page 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=&quot;s&quot; uri=&quot;/struts-tags&quot;%> Name: <s:textfield name=” name ”... entrance.jsp Find the name’s field name
  16. 16. Value Stack Find the object from the top of value stack to initialize the result page (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 Hamed Correct the name & trigger the action name=“ ” action class=“Entrance“ action method=“signIn“ 5 2 3 action=“submit“ 4 Hamed 2 1 field=“name” 1 Retrieve name property from action object
  17. 17. 1.name=“Hamed” 1 field=“ ” 2 <%@ taglib prefix=&quot;s&quot; uri=&quot;/struts-tags&quot;%> Name: <s:textfield name=” name ”... entrance.jsp name Find the name’s field
  18. 18. <s:form action = “ ” . . . <action name = “ ” class = “ ” method = “ ”> . . . Find the action name from “entrance.jsp” file Find the action class and method from &quot;struts.xml&quot; 1.name=“Hamed” 2.action class=“ “ 3.action method=“ “ 1 3 5 2.action=“ “ 4 submit Entrance signIn submit Entrance signIn entrance.jsp struts.xml submit field=“name” 2
  19. 19. Value Stack New Request So, new value stack object maker 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 5 2.action=“submit“ 4 3 1 2 field=“name” 2 3
  20. 20. Call the action method Return the return value entrance 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
  21. 21. 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
  22. 22. <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” Go to the result page 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=&quot;s&quot; uri=&quot;/struts-tags&quot;%> Welcome <s:property value=” name ”... welcome.jsp name field=“ ” 6
  23. 23. Value Stack Find the object from the top of value stack to initialize the result page (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

×