Struts Layers Components Overview

As we know that Struts follow MVC Architecture so there are three layer is Model-View-Controller. View is nothing but a presentation of data so instead of view here we use presentation layer.

Struts mainly deals with presentation layer and controller layer however it does not specify or force any rules related to Model layer so you can use anything(JDBC, Hibernate etc) in model layer as per your requirements.

Thus here we explain mainly two layer presentation and controller layer.

Struts Presentation Layer:

We can implement the following components in presentation layer of Struts Applications:
  1. JSP Elements.
  2. EL.
  3. JSTL
  4. Struts Tag Library.
  5. Message Bundles.
  6. Form Beans.
Here we explain briefly Struts Tag Library, Message Bundles and Form Bean

Struts Tag Library:  There are 6 tag library provided as :
  1. HTML Tag Library.
  2. Bean Tag Library.
  3. Logic Tag Library.
  4. Tiles Tag Library.
  5. Nested Tag Library.
  6. Template Tag Library.
Message Bundles: 
                               Message Bundles is nothing but a property file where we can define key-value pair. Message Bundles can be use to centralize two type of messages.
  • Labels
  1. Define the label in Message Bundle like as label.yourformname.yourformattributname=your message
  2. Access in jsp page like as <bean:message key=" label.yourformname.yourformattributname=your message "/>
  • Error Messages by validation
  1. Define the errors in Message Bundle as like  errors.yourformname.yourformattributname=your message
  2. Use the key to create the ActionError Object when you are adding ActionError Object to ActionErrors Object as like                                                                                           errors.add("mesg", new ActionError( "errors.yourformname.yourformattributname" ))
  3. Access in jsp page like as <html:errors property = "mesg"/>--show errors related to yourformattributename for all errors you can use as like <html:errrors/>
Form Beans:
                       There are 6 form beans provided as:
  1. ActionForm
  2. DynaActionForm
  3. ValidatorForm
  4. DynaValidatorForm
  5. ValidatorActionForm
  6. DynaValidatorActionForm
We will explain all of these in details in next tutorial.

Struts Controller Layer:

Here following are the controller layer components:
  1. Action Servlet
  2. Request Process(RP)
  3. Action
Action Servlet:  Action Servlet is the controller Servlet which is responsible for following:
  • Initialization struts configuration document
  • Receiving request and delegating to Request Processor.
Request Processor: Request Processor is responsible for receiving the request, procession the request completely and deliver the response to client.
Request Processor will do the following tasks while processing the request:
  • ActionMapping  procesMapping(...,URI)
  • ActionForm  processActionForm(....,ActionMapping)
  • void processPopulate(.....,ActionForm,ActionMapping)
  • boolen processValidate(......,ActionForm,ActionMapping)
  • Action processActionCreate(.....,ActionMapping)
  • ActionForward processActionPerform(.....,Action, ActionForm)
  • ActionForward processException(....,Exception, ActionForm, ActionMapping)
           or boolen processForward(.....,ActionMapping)
  • String processPath(.....)
Action: Action is the last component in the controller layer from where business layer starts.
 Action class we are writing may be subclass of one of the following Built-in-Actions.
  1. Action
  2. Dispatch Action
  3. LookupDispatch Action
  4. MappingDispatch Action
  5. Include Action
  6. Forward Action
  7. Switch Action
  8. Locale Action
  9. Download Action






2 comments :

  1. can you more define how we are implementing Model layer in struts through jdbc or struts

    ReplyDelete
  2. The components of struts layer are explained in effective manner moreover the blog gave us idea about the layers,libraries and message bundle thanks for the valuable post
    Java Training in Chennai

    ReplyDelete