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.

This entry was posted in Struts and tagged on by .

About Jitendra

Sr. Consultant at Cognizant Technology Solutions. Have more than 6 years of experience in technologies and frameworks like Salesforce, Node.Js, JAVA, PHP, JSP, Struts, Hibernate, C#, ASP.NET, SQL Server. Also many javaScript libraries like AngularJs, JQuery, JQuery Mobile, BootStrap. Connect : Linked In

  • Pingback: Simple Login Application in Struts 2 | Shiva Blog

  • 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

  • sanjay

    nice one…….thanks

  • 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.

    • JitendraZaa

      Thanks Raghunath for sharing and throwing light on this.

      Regards,
      Jitendra Zaa