Struts follows mvc2



Struts follows Mvc2

In struts ActonServlet acts as controller.it is responsible to proecess all the requests.so we have to configure Actionservlet in
web.xml of our struts application.


When user sends a request.Container checks for url pattern in web.xml.It forwards the request to ActionServlet which is configured in web.xml as a load on start up resource.Action servlet using helper class named RequestProcessor to create formbean object and populate submited form data into formbean properties.If there is a form bean object in request scope it will never create object.if not it will create form bean object.Then that form bean will be placed in the request scope.



    action
    
        org.apache.struts.action.ActionServlet
    
    
    config
    /WEB-INF/struts-config.xml
    
    1

ActionServlet is a servlet it is encapsulates ActionServlet is responsible to create Formbean and Action classes by using Struts-config.xml file.

We can validate our form in formbean class.Once validation was successfull then it calls Action class execute method.In Action class execute method we can get form bean class,ActionMapping ,HttpRequest and HttpResponse objects.From this method we are going to access our Dao class for persistance operations or we can call business deligator to execute our ejb also.

execute method returns action forward based on the result from bussinesslogic.Action servlet selects view from actionforward and renders the result using that resource.

FormBean: It is just like normal java bean class.Form bean class extends org.apache.struts.action.ActionForm class of struts framework.FormBean should contain a explicit defult constructor.Formbean have some properties,reset,validate methods.

Action class: It is like a servlet.Struts framework encapsultes servlet. Action class should extends org.apache.struts.action.Action class of Struts frame work. we should override execute method in our action class.we need to configure about formbean and action class inside struts-config.xml file.

Comments