Your SlideShare is downloading. ×
Struts
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Struts

1,079
views

Published on


0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,079
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
54
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Struts Workshop Presented By Rajkumar Singh www.rajkrrsingh.blogspot.com
  • 2. AgendaStruts 2 overviewRequest ,Response cycleStruts 2 architectureStruts 1 vs Struts 2Struts2 TagsValidator frameworkInterceptor and Custom InterceptorValueStack, OGNL and Type Converter www.rajkrrsingh.blogspot.com
  • 3. MVC www.rajkrrsingh.blogspot.com
  • 4. What is Struts2 Framework A framework tries to automate the common tasks and provides a platform for the users to build applications quickly. www.rajkrrsingh.blogspot.com
  • 5. What is Struts2 FrameworkStruts 2 is a very well-designed and flexible.An integration of Struts 1 with OpenSymphony Web WorksFramework www.rajkrrsingh.blogspot.com
  • 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. www.rajkrrsingh.blogspot.com
  • 7. What is Struts2 Framework www.rajkrrsingh.blogspot.com
  • 8. Struts 2 Architecture www.rajkrrsingh.blogspot.com
  • 9. Struts 2 Architecture www.rajkrrsingh.blogspot.com
  • 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. www.rajkrrsingh.blogspot.com
  • 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. www.rajkrrsingh.blogspot.com
  • 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. www.rajkrrsingh.blogspot.com
  • 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 .) www.rajkrrsingh.blogspot.com
  • 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. www.rajkrrsingh.blogspot.com
  • 15. Difference in Struts 1 and Struts 2 www.rajkrrsingh.blogspot.com
  • 16. Difference in Struts 1 and Struts 2 www.rajkrrsingh.blogspot.com
  • 17. Difference in Struts 1 and Struts 2 www.rajkrrsingh.blogspot.com
  • 18. Structure of URL www.rajkrrsingh.blogspot.com
  • 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> www.rajkrrsingh.blogspot.com
  • 20. Struts.xml www.rajkrrsingh.blogspot.com
  • 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 www.rajkrrsingh.blogspot.com
  • 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. www.rajkrrsingh.blogspot.com
  • 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 www.rajkrrsingh.blogspot.com
  • 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> www.rajkrrsingh.blogspot.com
  • 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 www.rajkrrsingh.blogspot.com
  • 26. Action/ValueStack/OGNL www.rajkrrsingh.blogspot.com
  • 27. QA www.rajkrrsingh.blogspot.com

×