Presentation is loading. Please wait.

Presentation is loading. Please wait.

Implementation Struts Framework for well-architectured web applications Model-View-Controller design pattern.

Similar presentations


Presentation on theme: "Implementation Struts Framework for well-architectured web applications Model-View-Controller design pattern."— Presentation transcript:

1

2 Implementation Struts http://jakarta.apache.org/struts/index.html Framework for well-architectured web applications Model-View-Controller design pattern Model: application state View: presentation of that data Controller:handles routing of app Separates three elements distinctly

3 Model – View – Controller

4 Struts Framework provides Central controller – ActionServlet All paths go through controller Configurable through xml Action classes Adaptors between business layer and web tier Can unit test at this level ActionForms Hold data for each jsp page Auto-magically updated

5 Struts – continued Framework provides… Tag libraries Avoid scriptlets Page designers can handle Built In Internationalization Build In Validation of user input Advantages Excellent architecture and design Reuse, modularity, extensibility etc.. Established framework Open source

6 Struts – general Architecture Each task a path Path contains info to do that task: Action class whose perform() method will be called Form Bean to hold data to / from view Forwards to pass control to on success / failure Input jsp – auto validate user input Graphically:

7 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 2Jsp 3 Form Bean 1 Form Bean 2 Other Bean 1 request/session Web Browser MarkVision Server path action [form bean] [forwards] Jsp 2 Web Server Jsp 2 CoreSession Socket

8 Example Step through show and save logging parameters Note extra beans which encapsulate interaction with server LoggingBean.java ServerBean.java

9 Web Server 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 looks up <action path="/ShowLogging" type="beans.ShowLoggingAction" name="LoggingForm"> <forward name="success“ path="/logging.jsp" /> ServerBean.java populates form values …. logging.jsp Messages Resources displays internationalized messages

10 Web Server 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("success") forwards – result.jsp expands custom tags Displays internationalized messages from bean response sent to browser – pure html looks up <action path="/SaveLogging" type="beans.SaveLoggingAction" name="LoggingForm"> <forward name="success“ path="/result.jsp" /> ServerBean.java Messages Bean add result messages auto populates using bean getters/setters becomes request parameter category[0].value added to form using LoggingForm.getCategory(0).setValue(value) For each one that user has changed… call business logic to change on server browser adds form variables to request results.jsp

11 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 2Jsp 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 path action [form bean] [forwards] 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 Action2.java Form Bean 2 Web Server Jsp 2


Download ppt "Implementation Struts Framework for well-architectured web applications Model-View-Controller design pattern."

Similar presentations


Ads by Google