SlideShare a Scribd company logo
Struts Overview Shakeel Mahate [email_address]
What is Struts Framework to develop web applications Open source Jakarta project http://jakarta.apache.org/struts/ Current release at 1.1 Beta 3 Based on MVC-Model 2 pattern
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
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
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
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”);
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
Resource Bundles Configures message resource bundles <message-resources parameter=“myApplication”/> Utilized to NLS enable application All static strings should be specified in myApplication.properties file Format: key=value Name.label=Enter first name
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”/>
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
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() /createUser.do
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 …”/>
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
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
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
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>
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”/>
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
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
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
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
How to develop Struts apps Use WSAD 5.0

More Related Content

PPTX
Controllers & actions
PPS
Introduction To Mvc
PPTX
jQuery basics
PDF
Jsf intro
PPT
ASP .net MVC
ODP
JSF 2.0 (JavaEE Webinar)
ODP
A Complete Tour of JSF 2
PDF
jQuery and Rails: Best Friends Forever
Controllers & actions
Introduction To Mvc
jQuery basics
Jsf intro
ASP .net MVC
JSF 2.0 (JavaEE Webinar)
A Complete Tour of JSF 2
jQuery and Rails: Best Friends Forever

What's hot (20)

PPT
jQuery and AJAX with Rails
PPT
CTTDNUG ASP.NET MVC
PPTX
Java Training Ahmedabad , how to Insert Data in Servlet, iOS Classes Ahmedabad
PDF
Manipulating Magento - Mage Titans Italy 2018
PPT
JSF Component Behaviors
PPTX
Jsp session implicit object
PDF
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
PPT
Struts Intro
PDF
Manipulating Magento - Meet Magento Belgium 2017
PPTX
Asp.Net MVC Intro
PPTX
Intro react js
PDF
Technical Preview: The New Shopware Admin
PDF
Ellicit forms and_reports
PDF
Jinal desai .net
PPTX
Introduction to JSF
PPT
MSDN - ASP.NET MVC
PPTX
Angular js 1.3 presentation for fed nov 2014
PPTX
Backbone.js and friends
PPTX
MVC & SQL_In_1_Hour
jQuery and AJAX with Rails
CTTDNUG ASP.NET MVC
Java Training Ahmedabad , how to Insert Data in Servlet, iOS Classes Ahmedabad
Manipulating Magento - Mage Titans Italy 2018
JSF Component Behaviors
Jsp session implicit object
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Struts Intro
Manipulating Magento - Meet Magento Belgium 2017
Asp.Net MVC Intro
Intro react js
Technical Preview: The New Shopware Admin
Ellicit forms and_reports
Jinal desai .net
Introduction to JSF
MSDN - ASP.NET MVC
Angular js 1.3 presentation for fed nov 2014
Backbone.js and friends
MVC & SQL_In_1_Hour
Ad

Viewers also liked (20)

PDF
JAVA EE training from 3rd-oct-2015
PPT
Struts2
PPTX
Struts & spring framework issues
PPT
Struts2
PPT
PPTX
Spring By Example One Day Workshop
PPTX
PDF
Struts2
PPTX
A PRESENTATION ON STRUTS & HIBERNATE
PDF
Hibernate 3
PPT
Hibernate architecture
PPTX
Introduction to j2 ee frameworks
PDF
Introduction to Java Enterprise Edition
PDF
Java Enterprise Edition
PPTX
Why do I hate Hibernate?
PPT
Java & J2EE Struts with Hibernate Framework
ODP
ORM, JPA, & Hibernate Overview
PDF
Creating modern java web applications based on struts2 and angularjs
PDF
Hibernate Presentation
JAVA EE training from 3rd-oct-2015
Struts2
Struts & spring framework issues
Struts2
Spring By Example One Day Workshop
Struts2
A PRESENTATION ON STRUTS & HIBERNATE
Hibernate 3
Hibernate architecture
Introduction to j2 ee frameworks
Introduction to Java Enterprise Edition
Java Enterprise Edition
Why do I hate Hibernate?
Java & J2EE Struts with Hibernate Framework
ORM, JPA, & Hibernate Overview
Creating modern java web applications based on struts2 and angularjs
Hibernate Presentation
Ad

Similar to Struts Overview (20)

PPT
08052917365603
PPT
Introducing Struts 2
PPT
Struts,Jsp,Servlet
PPT
Strutsjspservlet
PPT
Strutsjspservlet
PDF
Unit 07: Design Patterns and Frameworks (3/3)
PPT
DWR, Hibernate and Dojo.E - A Tutorial
PDF
Migrating from Struts 1 to Struts 2
PPT
Struts 2 + Spring
PPT
Automated Testing Of Web Applications Using XML
ODP
Os Leonard
PPT
Intoduction to Play Framework
PPTX
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
PPT
Jsfsunum
PPT
Seam Introduction
PPT
Struts2
PPTX
Spine.js
PDF
Java Web Programming [8/9] : JSF and AJAX
PPTX
Custom Action Framework
08052917365603
Introducing Struts 2
Struts,Jsp,Servlet
Strutsjspservlet
Strutsjspservlet
Unit 07: Design Patterns and Frameworks (3/3)
DWR, Hibernate and Dojo.E - A Tutorial
Migrating from Struts 1 to Struts 2
Struts 2 + Spring
Automated Testing Of Web Applications Using XML
Os Leonard
Intoduction to Play Framework
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Jsfsunum
Seam Introduction
Struts2
Spine.js
Java Web Programming [8/9] : JSF and AJAX
Custom Action Framework

More from elliando dias (20)

PDF
Clojurescript slides
PDF
Why you should be excited about ClojureScript
PDF
Functional Programming with Immutable Data Structures
PPT
Nomenclatura e peças de container
PDF
Geometria Projetiva
PDF
Polyglot and Poly-paradigm Programming for Better Agility
PDF
Javascript Libraries
PDF
How to Make an Eight Bit Computer and Save the World!
PDF
Ragel talk
PDF
A Practical Guide to Connecting Hardware to the Web
PDF
Introdução ao Arduino
PDF
Minicurso arduino
PDF
Incanter Data Sorcery
PDF
PDF
Fab.in.a.box - Fab Academy: Machine Design
PDF
The Digital Revolution: Machines that makes
PDF
Hadoop + Clojure
PDF
Hadoop - Simple. Scalable.
PDF
Hadoop and Hive Development at Facebook
PDF
Multi-core Parallelization in Clojure - a Case Study
Clojurescript slides
Why you should be excited about ClojureScript
Functional Programming with Immutable Data Structures
Nomenclatura e peças de container
Geometria Projetiva
Polyglot and Poly-paradigm Programming for Better Agility
Javascript Libraries
How to Make an Eight Bit Computer and Save the World!
Ragel talk
A Practical Guide to Connecting Hardware to the Web
Introdução ao Arduino
Minicurso arduino
Incanter Data Sorcery
Fab.in.a.box - Fab Academy: Machine Design
The Digital Revolution: Machines that makes
Hadoop + Clojure
Hadoop - Simple. Scalable.
Hadoop and Hive Development at Facebook
Multi-core Parallelization in Clojure - a Case Study

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Empathic Computing: Creating Shared Understanding
PDF
Approach and Philosophy of On baking technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Spectroscopy.pptx food analysis technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Empathic Computing: Creating Shared Understanding
Approach and Philosophy of On baking technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Spectroscopy.pptx food analysis technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
MIND Revenue Release Quarter 2 2025 Press Release
MYSQL Presentation for SQL database connectivity
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

Struts Overview

  • 1. Struts Overview Shakeel Mahate [email_address]
  • 2. What is Struts Framework to develop web applications Open source Jakarta project http://jakarta.apache.org/struts/ 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 myApplication.properties 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() /createUser.do
  • 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