100 likes | 241 Views
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.
E N D
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
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
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
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:
Jsp 2 Jsp 1 Jsp 2 Jsp 2 Jsp 3 Page 1 Web Browser Web Server request/session View Layer Form Bean 1 Jsp Engine Form Bean 2 Other Bean 1 Controller Struts- config. xml Mappings Action1 .java Action2 .java Action3 .java Action4 .java • path • action • [form bean] • [forwards] Business Logic Layer Business Bean 1 Business Bean 2 Business Bean 3 CoreSession Socket CoreSession Data Layer MarkVision Server
Example • Step through show and save logging parameters • Note extra beans which encapsulate interaction with server • LoggingBean.java • ServerBean.java
<form name="LoggingForm" …> <logic:iterate id="category“ name="LoggingForm" property="categoryList"> <bean:write name="category" property="key"/> <bean:write name="category" property="desc"/> …. </logic:iterate> </form> Web Server populates form values looks up Messages Resources <!-- Show logging --> <action path="/ShowLogging" type="beans.ShowLoggingAction" name="LoggingForm"> <forward name="success“ path="/logging.jsp" /> </action> logging.jsp logging.jsp index.htm Web Browser response sent to browser – pure html request/session Request: ShowLogging.do expands custom tags displays internationalized messages View Layer Jsp Engine Logging Form forwards – logging.jsp creates form bean in correct scope Controller setCategoryList(list) returns forward(success) perform(mapping, form, request, response) creates / reuses Mappings Show Logging Action .java mainpulates data calls business logic rule to get logging info Business Logic Layer LoggingBean.java ServerBean.java Data Layer Granite
<form name="LoggingForm" …> <select name="category[0].value" > </form> becomes request parameter category[0].value added to form using LoggingForm.getCategory(0).setValue(value) Web Server • • • • • • • auto populates using bean getters/setters looks up <!-- Save logging --> <action path="/SaveLogging" type="beans.SaveLoggingAction" name="LoggingForm"> <forward name="success“ path="/result.jsp" /> </action> results.jsp results.jsp logging.jsp Web Browser response sent to browser – pure html form submit – action=‘SaveLogging.do’ Displays internationalized messages from bean expands custom tags View Layer request/session Jsp Engine browser adds form variables to request Messages Bean Logging Form forwards – result.jsp reuses form bean in correct scope Controller getCategoryList() add result messages creates / reuses action instance returns mapping.findForward("success") calls perform(mapping, form, request, response) Mappings Show Logging Action .java For each one that user has changed… call business logic to change on server Business Logic Layer LoggingBean.java ServerBean.java Data Layer Granite
Web Server Form Bean 2 Action2 .java Jsp 2 Jsp 1 Jsp 2 Jsp 2 Jsp 3 Page 1 pure HTML sent to browser Web Browser processes custom tags – fill form elements from beans, display internationalized messages request/session View Layer incoming requests Form Bean 1 Jsp Engine Form Bean 2 Other Bean 1 relevant page called if submit, auto populates form bean from request params • • • creates/reuses any associated form bean • • • • Controller reads on start-up Struts- config. xml looks up path to determine action/ form bean creates passes control to relevant action to handle returns appropriate forward Mappings Action1 .java Action2 .java Action3 .java Action4 .java • path • action • [form bean] • [forwards] gets data to display (adds to beans in request/session)…or saves data from beans via business rules interacts with lower layers - acts as adaptor between HTTP and layers below Business Logic Layer Business Bean 1 Business Bean 2 Business Bean 3 Data Layer Business Data