What is Struts 2 and how it works

Struts 2 is the Open source web application Framework which simplified the creation of Web Applications in in Java. It is based on the Model – View – Framework (MVC) architect which is originally found in language “SmallTalk“.  Latest version of Struts is 2 and which is created by using concepts of WebWork and Xwork.

Flow of Struts 2:

How Struts 2 Works
How Struts 2 Works

 

  1. Request : Client makes the request.
  2. Filter Dispatcher : As Boot Strap component is specified in Deployment Descriptor file. In Case of Struts 2, it is Servlet Filter (Filter Dispatcher). Filter Dispatcher looks the request and then as per the mapping of URL, request is forwarded to appropriate Action Class.
  3. Interceptor Stacks : Before going to Action Class, request goes to Interceptor Stacks (Action class mapping found in configuration file, and from there, list of interceptors identified which must be processed before Action class) .
  4. Action Class : Then the request object is passed to Action Class. Action Class then executes the code and after execution it returns the result code to the Controller. (either SUCCESS or INPUT or ERROR)
  5. Result : On the basis of result code, Controller then selects View to be rendered as a result of Action.
  6. Interceptors Stack : Before sending response back to client, again interceptors run.
  7. Response returned to User.

Note: If interceptor changes the result return type then the view will be changed and decided after interceptor.


Posted

in

by

Tags:

Comments

6 responses to “What is Struts 2 and how it works”

  1. […] by Step Simple Login Application in Struts 2 Posted by Jitendra Zaa on March 24th, 2011 We have seen that what is struts and how it works. I will guide the new developer, step by step to create the login application using struts 2 in this […]

  2. murali Avatar
    murali

    hi Shiva,

    Nice tutorial about struts framework. But i need to clarify some basics about struts. Please share those knowledge with us.

    1. What is Framework?
    2. Why we need struts and spring?
    3. What is the advantage between servlets ans struts?

    Please reply for above question.

    Thanks

    1. Ashu Sharma Avatar
      Ashu Sharma

      Framework is a platform which contains lot of libraries and code which is necessary to design an application. So Framework makes the application development very fast and easy. We can say that Framework means Programming with the available libraries and Jars.

      Struts is used to develop the Web Application because Java is not sufficient to develop a web application.

      Spring removes the tight coupling between the objects. Spring ensures that the objects are not dependent on another object.

  3. sanjay Avatar
    sanjay

    nice one…….thanks

  4. Raghunath BJ Avatar
    Raghunath BJ

    In Struts2 we will have pre-processing and post-processing requests.

    Pre-processing requests are the requests when client fires a request then before reaching action class filter stack check would be to modify the request , this is called as pre-processing.

    Post processing means if response is ready to send to the client then before sending response , again filter stack can be applied to modify the response and then send the response back to the client.

    1. JitendraZaa Avatar
      JitendraZaa

      Thanks Raghunath for sharing and throwing light on this.

      Regards,
      Jitendra Zaa

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.