Implementation <ul><li>Struts </li></ul><ul><ul><li>http:// jakarta .apache.org/struts/index.html </li></ul></ul><ul><li>F...
Model – View – Controller
Struts <ul><li>Framework provides </li></ul><ul><ul><li>Central controller – ActionServlet </li></ul></ul><ul><ul><ul><li>...
Struts – continued <ul><li>Framework provides… </li></ul><ul><ul><li>Tag libraries </li></ul></ul><ul><ul><ul><li>Avoid sc...
Struts – general Architecture <ul><li>Each task a path </li></ul><ul><li>Path contains info to do that task: </li></ul><ul...
Page 1 Controller Action2 .java Struts- config. xml Mappings Business Logic Layer Data Layer View Layer Business Bean 1 Js...
Example <ul><li>Step through show and save logging parameters </li></ul><ul><li>Note extra beans which encapsulate interac...
creates / reuses index.htm Controller Show Logging Action .java Mappings Business Logic Layer Data Layer View Layer Jsp En...
creates / reuses action instance logging.jsp Controller Show Logging Action .java Mappings Business Logic Layer Data Layer...
if submit, auto populates form bean from request params Page 1 Controller Action2 .java Struts- config. xml Mappings Busin...
Upcoming SlideShare
Loading in...5
×

Struts Intro

901
-1

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
901
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
33
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Struts Intro

  1. 1. Implementation <ul><li>Struts </li></ul><ul><ul><li>http:// jakarta .apache.org/struts/index.html </li></ul></ul><ul><li>Framework for well-architectured web applications </li></ul><ul><li>Model-View-Controller design pattern </li></ul><ul><ul><li>Model: application state </li></ul></ul><ul><ul><li>View: presentation of that data </li></ul></ul><ul><ul><li>Controller: handles routing of app </li></ul></ul><ul><ul><li>Separates three elements distinctly </li></ul></ul>
  2. 2. Model – View – Controller
  3. 3. Struts <ul><li>Framework provides </li></ul><ul><ul><li>Central controller – ActionServlet </li></ul></ul><ul><ul><ul><li>All paths go through controller </li></ul></ul></ul><ul><ul><ul><li>Configurable through xml </li></ul></ul></ul><ul><ul><li>Action classes </li></ul></ul><ul><ul><ul><li>Adaptors between business layer and web tier </li></ul></ul></ul><ul><ul><ul><li>Can unit test at this level </li></ul></ul></ul><ul><ul><li>ActionForms </li></ul></ul><ul><ul><ul><li>Hold data for each jsp page </li></ul></ul></ul><ul><ul><ul><li>Auto-magically updated </li></ul></ul></ul>
  4. 4. Struts – continued <ul><li>Framework provides… </li></ul><ul><ul><li>Tag libraries </li></ul></ul><ul><ul><ul><li>Avoid scriptlets </li></ul></ul></ul><ul><ul><ul><li>Page designers can handle </li></ul></ul></ul><ul><ul><li>Built In Internationalization </li></ul></ul><ul><ul><li>Build In Validation of user input </li></ul></ul><ul><li>Advantages </li></ul><ul><ul><li>Excellent architecture and design </li></ul></ul><ul><ul><li>Reuse, modularity, extensibility etc.. </li></ul></ul><ul><ul><li>Established framework </li></ul></ul><ul><ul><li>Open source </li></ul></ul>
  5. 5. Struts – general Architecture <ul><li>Each task a path </li></ul><ul><li>Path contains info to do that task: </li></ul><ul><ul><li>Action class whose perform() method will be called </li></ul></ul><ul><ul><li>Form Bean to hold data to / from view </li></ul></ul><ul><ul><li>Forwards to pass control to on success / failure </li></ul></ul><ul><ul><li>Input jsp – auto validate user input </li></ul></ul><ul><li>Graphically: </li></ul>
  6. 6. Page 1 Controller Action2 .java Struts- config. xml Mappings Business Logic Layer Data Layer View Layer Business Bean 1 Jsp Engine Jsp 1 Action3 .java Action4 .java Action1 .java Business Bean 2 Business Bean 3 Jsp 2 Jsp 3 Form Bean 1 Form Bean 2 Other Bean 1 request/session Web Browser MarkVision Server <ul><li>path </li></ul><ul><li>action </li></ul><ul><li>[form bean] </li></ul><ul><li>[forwards] </li></ul>Jsp 2 Web Server Jsp 2 CoreSession CoreSession Socket
  7. 7. Example <ul><li>Step through show and save logging parameters </li></ul><ul><li>Note extra beans which encapsulate interaction with server </li></ul><ul><ul><li>LoggingBean.java </li></ul></ul><ul><ul><li>ServerBean.java </li></ul></ul>
  8. 8. creates / reuses index.htm Controller Show Logging Action .java Mappings Business Logic Layer Data Layer View Layer Jsp Engine LoggingBean.java logging.jsp Logging Form request/session Web Browser Granite Request: ShowLogging.do creates form bean in correct scope perform(mapping, form, request, response) calls business logic rule to get logging info returns forward(success) mainpulates data setCategoryList(list) forwards – logging.jsp expands custom tags response sent to browser – pure html ServerBean.java logging.jsp displays internationalized messages Web Server looks up <!-- Show logging --> <action path =&quot;/ShowLogging&quot; type =&quot;beans.ShowLoggingAction&quot; name =&quot;LoggingForm&quot;> < forward name=&quot;success“ path=&quot;/logging.jsp&quot; /> </action> populates form values <form name=&quot;LoggingForm&quot; …> <logic:iterate id=&quot;category“ name=&quot;LoggingForm&quot; property=&quot;categoryList&quot;> <bean:write name=&quot;category&quot; property=&quot;key&quot;/> <bean:write name=&quot;category&quot; property=&quot;desc&quot;/> … . </logic:iterate> </form> Messages Resources
  9. 9. creates / reuses action instance logging.jsp Controller Show Logging Action .java Mappings Business Logic Layer Data Layer View Layer Jsp Engine LoggingBean.java results.jsp Logging Form request/session Web Browser Granite form submit – action=‘SaveLogging.do’ reuses form bean in correct scope calls perform(mapping, form, request, response) getCategoryList() returns mapping.findForward(&quot;success&quot;) forwards – result.jsp expands custom tags Displays internationalized messages from bean response sent to browser – pure html ServerBean.java Messages Bean add result messages For each one that user has changed… call business logic to change on server browser adds form variables to request results.jsp Web Server looks up <!-- Save logging --> <action path =&quot;/SaveLogging&quot; type =&quot;beans.SaveLoggingAction&quot; name =&quot;LoggingForm&quot;> < forward name=&quot;success“ path=&quot;/result.jsp&quot; /> </action> auto populates using bean getters/setters <form name=&quot;LoggingForm&quot; …> <select name=&quot;category[0].value&quot; > </form> becomes request parameter category[0].value added to form using LoggingForm.getCategory(0).setValue(value) • • • • • • •
  10. 10. if submit, auto populates form bean from request params Page 1 Controller Action2 .java Struts- config. xml Mappings Business Logic Layer Data Layer View Layer Business Bean 1 Jsp Engine Jsp 1 Action3 .java Action4 .java Action1 .java Business Bean 2 Business Bean 3 Jsp 2 Jsp 3 Form Bean 1 Form Bean 2 Other Bean 1 request/session Web Browser Business Data reads on start-up creates incoming requests creates/reuses any associated form bean <ul><li>path </li></ul><ul><li>action </li></ul><ul><li>[form bean] </li></ul><ul><li>[forwards] </li></ul>passes control to relevant action to handle interacts with lower layers - acts as adaptor between HTTP and layers below gets data to display (adds to beans in request/session)…or saves data from beans via business rules looks up path to determine action/ form bean returns appropriate forward relevant page called processes custom tags – fill form elements from beans, display internationalized messages pure HTML sent to browser Jsp 2 • • • • • • • Jsp 2 Action2 .java Form Bean 2 Web Server
  1. Gostou de algum slide específico?

    Recortar slides é uma maneira fácil de colecionar informações para acessar mais tarde.

×