Your SlideShare is downloading. ×
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
Struts Overview
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 Overview


Published on

Published in: Technology, Education
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Struts Overview Shakeel Mahate [email_address]
  • 2. What is Struts
    • Framework to develop web applications
    • Open source Jakarta project
    • Current release at 1.1 Beta 3
    • Based on MVC-Model 2 pattern
  • 3. What is MVC-Model 2 Browser Controller Servlet Model JavaBean View JSP HTML Stylesheets Form submit HTTP Event HTTP Response Get property Forward Create/Set property Business Layer
  • 4. What is Struts MVC-Model 2 Browser Controller ActionServlet Model JavaBean View JSP Business Layer ActionForm Struts- Config. xml Business Logic Action Resource Bundle create Http Event Http Response forward dispatch create/set get forward
  • 5. What is ActionServlet
    • Traffic cop
    • Part of the Struts Framework
    • Consults struts-config.xml to determine Action – ActionForm mapping
    • Transforms request parameters into ActionForm
      • Type safety, validation
  • 6. What is Action
    • Extend org.apache.struts.action.Action
    • Override execute()
    • Talk to your business layer to perform the action
    • Populates data in request/session scope
    • Tells Struts which page to display
      • return mapping.findForward(“displayResults”);
  • 7. What is struts-config.xml
    • Similar to web.xml which configures logical names for Servlets and specifies the Java class name
    • Configures action mappings, form beans, forwards (views), resource bundles, plugins
  • 8. Resource Bundles
    • Configures message resource bundles
    • <message-resources parameter=“myApplication”/>
    • Utilized to NLS enable application
    • All static strings should be specified in file
    • Format: key=value
      • Name.label=Enter first name
  • 9. Global forwards
    • Remember RequestDispatcher.forward() method – hence the name forward!!!
    • Logical name for all global filenames
    • Level of indirection
    • NO FILENAMES in execute()
      • <forward name=“displayResults”
      • path=“/pages/default.jsp”/>
  • 10. Action Mappings
    • Maps a form name to an Action
    • Every form has an ActionForm
    • Associates Java class name to an Action
    • Associates an input page to an Action
      • Page that triggered this action
      • Used for handling validation errors
    • Associates result pages (forwards) to an Action
  • 11. Action Mapping
    • <action path=“/createUser”
    • type=“… Java class name …”
    • scope=“request | session | application”
    • input=“another action or jsp”
    • name=“form bean name”>
    • <forward name=“…” path=“…”/>
    • <forward name=“…” path=“…”/>
    • </action>
    Utilized by mapping. findForward() /
  • 12. Form Beans
    • Instantiated by ActionServlet before invoking Action.execute()
    • How does ActionServlet know which form bean?
    • How does it know which Java class?
      • Struts-config.xml
      • <form-bean name=“…”
      • type=“… Java class name …”/>
  • 13. Form Bean Instantiation
    • ActionServlet checks the appropriate scope for the form bean before calling class.newInstance()
    • Populates data from the request parameters and does type conversion
    • Check out BeanUtils in Jakarta Commons project
  • 14. How to write Form Beans
    • Zero argument constructor
    • Public getters/setters
    • DO NOT USE ENTITY BEANS as form beans
    • Use Data Transfer Objects (Value Objects)
    • Decouple web app from business layer
  • 15. View
    • JSP or HTML pages
    • Use Struts tag library, JSTL tag library
    • DO NOT HARD CODE labels
      • Utilize ResourceBundle
    • Uses beans stored in request or session or application scope
  • 16. Simple View
    • <html:form action=“… form bean name …”>
    • <bean:message key=“name.label”/>
    • <html:text property=“name”/>
    • <html:submit>
    • … Name of the button…
    • </html:submit>
    • </html:form>
  • 17. Validation
    • Override validate() in ActionForm
      • public ActionErrors validate(ActionMapping map, HttpServletRequest req) {
      • ActionErrors errors = new ActionErrors();
      • if (name==null || name.length() < 1)
      • errors.add(“nameMissing”, new ActionError(“msg.key”));
      • return errors;
      • }
    • Add the following to Input page
      • <html:errors property=“nameMissing”/>
  • 18. Validator package
    • Automatically generate client side JavaScript code
    • Specify WEB-INF/validation.xml
      • Define regular expressions for validating data, phone#, social security#, etc.
      • For each form specify required fields
    • Augment rules in WEB-INF/validator-rules.xml
  • 19. No need to write ActionForm
    • Dynamically generate ActionForm class for your forms
    • Specify form fields in struts-config.xml
    • Basic idea is properties of a bean are a HashMap
    • Again check Jakarta Commons Project
  • 20. Modular Struts
    • Typical web app development consists of 4-5 programmers
    • Struts-config.xml is the bottleneck
    • Create Modules (or folders) with their own struts-config.xml
  • 21. Tiles
    • Templates for Web pages
    • Layout various tiles of a web page
      • Header, Navigation, Body, Footer
    • Specified in tiles-definition.xml
      • Specifies the layout
      • Logical names for various tiles
      • Associate filenames to the tiles
  • 22. How to develop Struts apps
    • Use WSAD 5.0