This broadly covers Introduction to MVC , What is MVC1 and MVC2 , Struts 1 (Use of MVC) , Struts 2 Introduction & Difference between Struts 1 and Struts 2.
2. Presenter: Jyoti Kar, Mindfire Solutions
AGENDA
* Introduction to MVC
* What is MVC1 and MVC2
* Struts 1 (Use of MVC)
* Struts 2 Introduction
* Difference between Struts 1 and Struts 2
3. Presenter: Jyoti Kar, Mindfire Solutions
UNDERSTANDING MVC
* MVC is an architectural pattern.
* Separates application logic and presentation.
* Loose coupling of components.
* Adds flexibility to the development process.
* Components – Model , View and Controller.
5. Presenter: Jyoti Kar, Mindfire Solutions
MVC 1 ARCHITECTURE
* MVC1 associates the presentation logic with the
business logic.
* In MVC 1, controller and model,both are JSP.
* Doesn't support re usability of application
components.
6. Presenter: Jyoti Kar, Mindfire Solutions
MVC 2 ARCHITECTURE
* MVC 2 isolates the presentation logic from business
logic.
* In MVC 2 controller is servlet and model is java class.
* Supports re usability of application components.
7. Presenter: Jyoti Kar, Mindfire Solutions
WHAT IS STRUTS
* Struts is an open source Web application framework
developed as Apache Jakarta project.
* Model-View-Controller (MVC) framework.
* 3 Major Components in Struts
– Servlet controller (Controller)
– JSP or any other presentation technology (View)
– Application Business Logic in the form of
whatever suits the application (Model)
* Struts is focused on Controller
– Struts is Model and View independent.
9. Presenter: Jyoti Kar, Mindfire Solutions
CONTROLLER COMPONENTS IN STRUTS
* ActionServlet (Provided by Struts)
– Process user requests.
– Determine what the user is trying to achieve
according to the request.
– Pull data from the model (if necessary) to be
given to the appropriate view, and select the
proper view to respond to the user.
* RequestProcessor (Provided by Struts)
– Determine the ActionMapping associated with
this path.
– Instantiate the ActionForm associated with the
mapping and place it into the appropriate scope.
10. Presenter: Jyoti Kar, Mindfire Solutions
– Populate the ActionForm associated with this
request, if any.
– Perform validation (if requested) on the
ActionForm associated with this request (if any) .
– Instantiate an instance of the Action class
specified by the ActionMapping and calls the
execute() method.
– Finally, the process method of the
RequestProcessor takes the ActionForward
returned by your Action class, and uses to select
the next resource (if any).
11. Presenter:Jyoti Kar, Mindfire Solutions
* Action
– Extend org.jakarta.struts.action.Action
– Process client request by calling other objects
(BusinessLogic beans) inside its execute()
Method.
– Returns an ActionForward object that identifies
where control should be forwarded.
Public ActionForward execute(ActionMapping mapping,
ActionForm form,HttpServletRequest Request,
HttpServletResponse response)throws Exception;
12. Presenter: Jyoti Kar, Mindfire Solutions
* Action Form Bean
– Extends Action Form class defined by Struts.
– Contains only property getter and property setter
methods for each field-no business logic.
– Provides standard validation mechanism.
* Action Mapping
– Action mapping is specified in struts-config.xml .
– Struts framework creates ActionMapping object
and passes it to Action object.
13. Presenter: Jyoti Kar, Mindfire Solutions
* struts-config.xml contains three important
elements used to describe actions:
– <form-beans>contains FormBean definitions
Including name and type (classname).
– <action-mapping> contains action definitions
Use an <action> element for each action defined.
– <global-forwards>contains your global forward
definitions.
14. Presenter: Jyoti Kar, Mindfire Solutions
<struts-config>
<!-- ========== Form Bean Definitions ================= -->
<form-beans>
<form-bean name = "submitForm"
type = "com.mindfire.SubmitForm"/>
</form-beans>
<!-- ========== Global Forward Definitions ============ -->
<global-forwards type="org.apache.struts.action.ActionForward">
<forward name="logon"
path="/logon.jsp" />
</global-forwards>
16. Presenter: Jyoti Kar, Mindfire Solutions
MODEL COMPONENTS IN STRUTS
* ActionForm Bean
– ActionFormBean can be regarded as a Model
component.
* SystemState Bean
– This is a conceptual term: Struts does not
provide any programming API.
* BusinessLogic Bean
– This is a conceptual term: Struts does not
provide any programming API.
17. Presenter: Jyoti Kar, Mindfire Solutions
VIEW COMPONENTS IN STRUTS
* JSP files
* Tag libraries
* Resource files for internationalization.
18. Presenter: Jyoti Kar, Mindfire Solutions
VIEW COMPONENTS IN STRUTS
* JSP files
* Tag libraries
* Resource files for internationalization.
20. Presenter: Jyoti Kar, Mindfire Solutions
REQUEST LIFE CYCLE
* User sends a request to the server.
* The FilterDispatcher looks at the request and
then determines the appropriate Action.
* Configured interceptors functionality applies
such as validation, file upload etc.
* Selected action is executed to perform the
requested operation.
* Finally the result is prepared by the view and
returns the result to the user.
21. Presenter: Jyoti Kar, Mindfire Solutions
DIFFERENCE BETWEEN STRUTS1 & STRUTS2
* In Struts2 Action class is POJO.
* Struts2 actions are instantiated for each request.
* Struts2 Actions are independent of Servlet API .
* Action form is not required rather action
properties are used in Struts 2.
* Struts2 supports annotations.