Published on

  • Be the first to comment


  1. 1. Struts Workshop Presented By Rajkumar Singh
  2. 2. AgendaStruts 2 overviewRequest ,Response cycleStruts 2 architectureStruts 1 vs Struts 2Struts2 TagsValidator frameworkInterceptor and Custom InterceptorValueStack, OGNL and Type Converter
  3. 3. MVC
  4. 4. What is Struts2 Framework A framework tries to automate the common tasks and provides a platform for the users to build applications quickly.
  5. 5. What is Struts2 FrameworkStruts 2 is a very well-designed and flexible.An integration of Struts 1 with OpenSymphony Web WorksFramework
  6. 6. What is Struts2 FrameworkStruts 2 framework implements the Model-View-Controller (MVC)design pattern.–Model- use any data access technologies like JDBC, EJB, Hibernateetc–View- integrated with JSP, JSTL, JSF, JakartaVelocity, Templates, PDF, XSLT etc.–Controller- based on many standard technologies like JavaFilters, Java Beans, ResourceBundles, XML etc.
  7. 7. What is Struts2 Framework
  8. 8. Struts 2 Architecture
  9. 9. Struts 2 Architecture
  10. 10. The Core ComponentsController : Filter dispatcher, by which all the requests to theapplications gets filtered.Interceptors : called after filters, apply common functionalities likevalidation, conversion etc before Action methods.Action : has execute methods, usually storing and/or retrievinginformation from a database for the view,i.e the jsp files.Result : Render the output as a view component i.e jsp file.
  11. 11. Request Cycle:1.Container pass request to filter chain.2.Chain includes the (optional) ActionContextCleanUp filter (usefulwhen integrating technologies such as SiteMesh Plugin)3.Required FilterDispatcher is called and consults with ActionMapperto determine if the request should invoke an action.4.If Action should be invoked, the FilterDispatcher delegates control tothe ActionProxy.5.The ActionProxy consults the framework Configuration Filesmanager (initialized from the struts.xml file).6.Next, the ActionProxy creates an ActionInvocation, which isresponsible for the command pattern implementation.7.This includes invoking any Interceptors in advance of invoking theAction itself.
  12. 12. Response Cycle:1. When Action returns, the ActionInvocation=>looking up=>Actionresult code mapped in struts.xml.2.The result is then executed, which often involves a template written inJSP to be rendered.3.While rendering, the templates can use the Struts Tags provided by theframework.4.Interceptors are executed again in reverse order.5.If the ActionContextCleanUp filter is present, the FilterDispatcher will notclean up the ThreadLocal ActionContext. (One can use ThreadLocal tokeep certain objects/values available throught the thread execution.)6.If the ActionContextCleanUp filter is not present, the FilterDispatcher willcleanup all ThreadLocals.
  13. 13. Why Struts 2 - FeaturesSimplified Design–Classes are based on interfaces–Action classes are simple POJOsSimplified Actions–Any java class with execute() method can be used as an Actionclass.–Inversion of Control is introduced while developing the actionclasses•(actions to be neutral to the underlying framework .)
  14. 14. Why Struts 2 - FeaturesNo more Action FormsAnnotations introducedStateful CheckboxesEasy Spring integrationEasy pluginAJAX supportBetter Tag featuresBoth JSP and FreeMarker tags are fully supported.
  15. 15. Difference in Struts 1 and Struts 2
  16. 16. Difference in Struts 1 and Struts 2
  17. 17. Difference in Struts 1 and Struts 2
  18. 18. Structure of URL
  19. 19. Struts.xml Core configuration file for framework. Can contain multiple package. <struts> <package name=“base” extends=“struts-default” namespace=“/”> <action name=“. . . .”> <result>. . . . . . . </action> </package> <include file=“hr.xml”/> </struts>
  20. 20. Struts.xml
  21. 21. Struts-default.xmlShipped in struts2-core.x.x.jarMost of your packages will extends Directly / IndirectlyContains about everything you need.Package from inheritance hierarchy.The Key section arepackageresult-Typeinterceptors/stack
  22. 22. InterceptorsResponsible for most of the processing done by the framework. Handle most of the fundamental preprocessing and post-processingtasks. Instead of invoking an action directly, this sits between the controller andthe action. The invocation of an action is a layered process that always includes theexecution of a stack of interceptors prior to and after the actual executionof the action itself.
  23. 23. Struts2 tagsStruts2 support following types of tagsA.UI Tags i.Form Tags ii.Non Form UI Tags iii.Ajax TagsB.Generic Tags i.Control Tags ii.Data Tags
  24. 24. Struts2 tags A.UI Tags render the HTML form and non-form componnets. <textfield> <password> <hidden> <textarea> <radio> <checkbox> <checkboxlist> <select> <combobox> <head> <file>
  25. 25. OGNL•Powerful expression language that is used to reference andmanipulate data on the ValueStack.•Helps in data transfer and type conversion.•Very similar to the JSP Expression Language.•Based on a context and Struts builds an ActionContext map for usewith OGNL.•The ActionContext map consists of the following:•application - application scoped variables•session - session scoped variables•root / value stack - all your action variables are stored here•request - request scoped variables•parameters - request parameters•atributes - the attributes stored in page, request, session andapplication scope
  26. 26. Action/ValueStack/OGNL
  27. 27. QA