• Resources
  • Downloads
  • Whats New!
  • Hibernate Tutorials

    Introduction to Struts Framework

    Author
    August 20, 2011 0 Comments
    Written by

    **Note: In order to follow the tutorial of Struts Framework for java you should have minimum knowledge on Servlets and JSPs

    I make you understand the concepts by answering to the questions.

    What is Struts?

    It is a web MVC based framework from Apache Software Foundation. That is the applications can need not be developed from scratch. Framework simplifies application development process.

    this above question raises another term known as Framework, now What is a Framework?

    Set of well defined classes and interfaces provides low level services to our application. (or) Set of well defined objects( 3rd party vendor given which provides some low level services to our applications i.e., it provides a reusable base.Examples of frameworks in case of java include your Struts MVC base framework, JSF, Spring etc.,

    Struts follows which architecture?

    MVC architectural design pattern.

    What is design pattern?

    It is a solution for common problem (reoccurring problem)

    MVC (Model View Controller)

    We are having a problem in developing applications as to how we can divide our application in to different modules. MVC architectural design pattern says that simply divide your application in to 3 parts namely, Model, View, Controller so as to reduce complexity in application development.

    MVC

    What is the difference between a library and a framework?

    What is the difference between library and a framework?

    Library is collection set of classes and interfaces and Framework is also set of classes and interfaces only. Then here only comes a question that what is the difference between a Library and a Framework? well, the difference is in the request. If the request is given to the application and our application interacts with 3rd party service to produce the response, then this 3rd party service is called to be a Library. On the other hand, if the client request is given to 3rd party services first and by interacting with our application it produces the response, then the 3rd party service in that context is called to be a Framework.

    General MVC Architecture

    General MVC Architecture

    MVC offers proper responsibility divison.

    Architectures specific to JAVA:

    1)MODEL-1 (Page centric architecture)

    2)MODEL-2 (MVC for JAVA)

    1)MODEL-1 (Page centric architecture)

    MODEL-1(Page Centric Architecture

     

     

    • This architecture describes design a single page which is responsible for accepting the client request integrating it with various business components, preparing the presentation and rendering presentation to client.
    • In this architecture, controller logic is tightly coupled with presentation logic.
    • In this architecture, single page is developed using JSP and business components are JavaBeans, EJBs etc.,
    • This architecture is suited for small scale projects.

    1)MODEL-2 (MVC for Java)

    MODEL-2 (MVC for Java)

    1. Request from the client to Controller.
    2. Access model and invokes business logic.
    3. Connected to database, perform CRUD (Create, Read, Update and Delete) operations.
    4. Collecting response content from model components
    5. Dispatching control to the JSP
    6. Preparing result and giving response to the client.

    In this architecture, controller logic is separated from presentation logic and controller components are developed using Servelts, View components are developed using JSPs, Model components are developed using JavaBeans or EJBs etc.,

    In the above architecture(MVC for Java), if no.of client requests are increased then it puts more load on single controller components, then again we are getting some problems like

    1) Decentralized accessibility.

    2)Code duplication. etc.,

    To resolve the above problems and to understand the Struts Framework clearly, we have to learn two design patterns namely,

    a) Front Controller

    b) Application Controller.

    In order to address above problems namely, Decentralized accessibility and Code duplication we are going for Front Controller Design Pattern.

    Responsibilities of Front Controller.

    1. Accepting the client request.
    2. Identifying the right worker component and delegating the request to it.
    3. Collecting response content from worker components.
    4. Dispatching the control to right view component.

    Front Controller Desingn Pattern

    What is the use of <load-on-startup> tag in web applications?

    This tag is a pre initialization tag. i.e., when ever container encounters this tag, then it immediately instantiates and initializes the corresponding Servlet. That when ever we get a request from the client for the first time, if we don’t place <load-on-startup> tag, then it requires additional time for instantiating and initializing of all servlets

    Application Controller

    • In the architecture of FrontController, if worker components are increased then again load on FrontController is getting increased.
    • To resolve this problem, ApplicationController design pattern is came into existence.


    In the above architecture, FrontController is responsible for providing single entry point to our system i.e, each and every client request must be channeled through FC only as well as ApplicationController (AC) is responsible for worker management as well as view management.

    Next Article on STRUTS architecture and building basic Struts application

     

    Tagged As


    A Software Developer and a Technology blogger from Hyderabad, India . With over 4 years of experience of algorithmic and design skills in developing highly scalable applications, specializing in Java & J2EE technologies.,aspires to be a tech geek, likes to learn new technology stuff. Through this blog, I'll try to share what all i have learned in past years of my career. Hope it helps!

    © 2010-2014 J2eeDev

    The content is copyrighted to Umashankar and may not be reproduced on other websites.