SlideShare a Scribd company logo
Introduction to Jakarta Struts 1.3
Ilio Catallo – info@iliocatallo.it
Outline
¤ Model-View-Controller vs. Web applications
¤ From MVC to MVC2
¤ What is Struts?
¤ Struts Architecture
¤ Building web applications with Struts
¤ Setting up the Controller
¤ Writing Views
¤ References
2
Model-View-Controller vs.
Web applications
3
Model-View-Controller
design pattern
¤ In the late seventies, software architects saw applications
as having three major parts:
¤ The part that manages the data (Model)
¤ The part that creates screens and reports (View)
¤ The part that handles interactions between the user and the
other subsystems (Controller)
¤ MVC turned out to be a good way to design applications
¤ Cocoa (Apple)
¤ Swing (Java)
¤ .NET (Microsoft)
4
Model-View-Controller
design pattern
5
View
Controller
Model
State query
Change notification
Event
Method
invocation
Model-View-Controller vs.
Web applications
¤ What is the reason not to use the same MVC pattern also
for web applications?
¤ Java developers already have utilities for:
¤ building presentation pages, e.g., JavaServer Pages (View)
¤ handling databases, e.g., JDBC and EJB (Model)
¤ But…
¤ the HTTP protocol imposes limitations on the applicability of
the MVC design pattern
¤ we don’t have any component to act as the Controller
6
HTTP limitations
¤ The MVC design pattern requires a push protocol for the
views to be notified by the model
¤ HTTP is a pull protocol: no request implies no response
¤ The MVC design pattern requires a stateful protocol to
keep track of the state of the application
¤ HTTP is stateless
7
HTTP limitations: Struts solutions
¤ HTTP is stateless: we can implement the MVC design
pattern on top of the Java Servlet Platform
¤ the platform provides a session context to help track users in
the application
¤ HTTP is a pull protocol: we can increase the Controller
responsibility. It will be responsible for:
¤ state changes
¤ state queries
¤ change notifications
8
Model-View-Controller 2
design pattern
¤ The resulting design pattern is sometimes called MVC2 or
Web MVC
¤ Any state query or change notification must pass through
the Controller
¤ The View renders data passed by the Controller rather than
data returned directly from the Model
9
View Controller Model
What is Jakarta Struts?
¤ Jakarta Struts is an open source framework
¤ It provides a MVC2-style Controller that helps turn raw
materials like web pages and databases into a coherent
application
¤ The framework is based on a set of enabling
technologies common to every Java web application:
¤ Java Servlets for implementing the Controller
¤ JavaServer Pages for implementing the View
¤ EJB or JDBC for implementing the Model
10
Struts Architecture
11
Struts Main Components:
ActionForward, ActionForm, Action
¤ Each web application is made of three main
components:
¤ Hyperlinks lead to pages that display data and other
elements, such as text and images
¤ HTML forms are used to submit data to the application
¤ Server-side actions which performs some kind of business
logic on the data
12
Struts Main Components:
ActionForward, ActionForm, Action
¤ Struts provides components that programmers can use to
define hyperlinks, forms and custom actions:
¤ Hyperlinks are represented as ActionForward objects
¤ Forms are represented as ActionForm objects
¤ Custom actions are represented as Action objects
13
Struts Main Components:
ActionMapping
¤ Struts bundles these details together into an
ActionMapping object
¤ Each ActionMappinghas its own URI
¤ When a specific resource is requested by URI, the
Controller retrieves the corresponding ActionMapping
object
¤ The mapping tells the Controller which Action, ActionForm
and ActionForwards to use
14
Struts Main Components:
ActionServlet
¤ The backbone component of the Struts framework is
ActionServlet (i.e., the Struts Controller)
¤ For every request, the ActionServlet:
¤ uses the URI to understand which ActionMapping to use
¤ bundles all the user input into an ActionForm
¤ call the Action in charge of handling the request
¤ reads the ActionForwardcoming from the Action and
forward the request to the JSP page what will render the
result
15
Struts Control Flow
16
Controller
(ActionServlet)
Action
(ActionMapping,
ActionForm)
JSP page
(with HTML
form)
JSP page
(result page)
HTTP
request
HTTP
response
①
②
③
④ Model
(e.g., EJB)
ActionForward
⑤
Controller Model
Struts main component responsibilities
Class Description
ActionForward A user’s gesture or view selection
ActionForm The data for a state change
ActionMapping The state change event
ActionServlet The part of the Controller that receives
user gestures and stare changes and
issues view selections
Action classes The part of the Controller that interacts
with the model to execute a state
change or query and advises
ActionServlet of the next view to select
17
Building Web applications with
Struts
Setting up the Controller
18
Setting up the Controller:
The big picture
19
struts-
config.xml
web.xml
ActionMapping 1 ActionMapping N
Setting up the Controller:
Servlet Container (1/3)
¤ The web.xml deployment descriptor file describes how to
deploy a web application in a servlet container (e.g., Tomcat)
¤ The container reads the deployment descriptor web.xml, which
specifies:
¤ which servlets to load
¤ which requests are sent to which servlet
20
Setting up the Controller:
Servlet Container (2/3)
¤ Struts implements the Controller as a servlet
¤ Like all servlets it lives in the servlet container
¤ Conventionally, the container is configured to sent to
ActionServlet any request that matches the pattern
*.do
¤ Remember: Any valid extension or prefix can be used,
.do is simply a popular choice
21
Setting up the Controller:
Servlet Container (3/3)
web.xml (snippet)
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
22
¤ Forward any request that matches the pattern *.do to
the servlet named action (i.e., the Struts controller)
Struts Controller:
struts-config.xml
¤ The framework uses the struts-config.xml file as a
deployment descriptor
¤ It contains all the ActionMappings definedfor the web
application
¤ At boot time, Struts reads it to create a database of objects
¤ At runtime, Struts refers to the object created with the
configuration file, not the file itself
23
Struts Controller:
ActionForm (1/4)
¤ A JavaBean is a reusable software component which
conform to a set of design patterns
¤ The access to the bean’s internal state is provided through
two kinds of methods: accessors and mutators
¤ JavaBeans are used to encapsulate many objects into a
single object
¤ They can be passed around as a single bean object instead
of as multiple individual objects
24
Struts Controller:
ActionForm (2/4)
¤ Struts model ActionForms as JavaBeans
¤ The ActionForm has a corresponding property for each field
on the HTML form
¤ The Controller matches the parameters in the HTTP
request with the properties of the ActionForm
¤ When they correspond, the Controller calls the setter
methods and passes the value from the HTTP request
25
Struts Controller:
ActionForm (3/4)
LoginForm.java
pubic class LoginForm extends org.apache.struts.action.ActionForm {
private String username;
private String password;
public String getUsername() {return this.username;}
public String getPassword() {return this.password;}
public void setUsername(String username) {this.username =
username;}
public void setPassword(String password) {this.password =
password;}
}
26
¤ An ActionForm is a JavaBean that extends
org.apache.struts.action.ActionForm
Struts Controller:
ActionForm (4/4)
Specifying a new ActionForm in struts-config.xml
<form-beans>
<form-bean name=”loginForm"
type=”app.LoginForm"/>
</form-beans>
27
¤ Define a mapping between the actual ActionForm and
its logical name
Struts Controller:
ActionForwards
Specifying new ActionForwardsin struts-config.xml
<forward name="success" path="/success.html"/>
<forward name=”failure" path="/success.html"/>
<forward name=”logon" path=”/Logon.do"/>
28
¤ Define a mapping between the resource link and its
logical name
¤ Once defined, throughout the web application it is
possible to reference the resource via its logical name
Struts Controller:
Action
¤ Actions are Java classes that extend
org.apache.struts.Action
¤ The Controller populates the ActionForm and then passes it
to the Action
¤ the entry method is perform (Struts 1.0) or execute (Struts 1.1+)
¤ The Action is generally responsible for:
¤ validating input
¤ accessing business information
¤ determining which ActionForward to return to the Controller
29
Struts Controller:
Action
LoginAction.java
import javax.servet.http.*;
public class LoginAction extends org.apache.struts.action.Action {
public ActionForward execute(ActionMapping mapping, ActionForm
form,
HttpServletRequest req, HttpServletResponse
res) {
// Extract data from the form
LoginForm lf = (LoginForm) form;
String username = lf.getUsername();
String password = lf.getPassword();
// Apply business logic
UserDirectory ud = UserDirectory.getInstance();
if (ud.isValidPassword(username, password))
return mapping.findForward("success");
return mapping.findForward("failure");
}
} 30
Struts Controller:
struts-config.xml
struts-config.xml (snippet)
<form-beans>
<form-bean name="loginForm"
type="app.LoginForm"/>
</form-beans>
<action-mappings>
<action path="/login"
type="app.LoginAction"
name="loginForm">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/failure.jsp"/>
</action>
</action-mappings>
31
Struts trims
automatically
the .do
extension
Building web applications with
Struts
Writing Views
32
Writing Views:
JavaServer Pages (JSP)
¤ JavaServer Pages is a technology that helps Java
developers create dynamically generated web pages
¤ A JSP page is a mix of plain old HTML tags and JSP scripting
elements
¤ JSP pages are translated into servlets at runtime by the JSP
container
33
JSP Scripting Element
<b> This page was accessed at <%= new Date() %></b>
Writing Views:
JSP tags
¤ JSP scripting elements require that developers mix Java
code with HTML. This situation leads to:
¤ non-maintainable applications
¤ no opportunity for code reuse
¤ An alternative to scripting elements is to use JSP tags
¤ JSP tags can be used as if they were ordinary HTML tags
¤ Each JSP tag is associated with a Java class
¤ It’s sufficient to insert the same tag on another page to reuse
the same code
¤ If the code changes, all the pages are automatically updated
34
Writing Views:
JSP Tag Libraries
¤ A number of prebuilt tag libraries are available for
developers
¤ Example: JSP Standard Tag Library (JSTL)
¤ Each JSP tag library is associated with a Tag Library
Descriptor (TLD)
¤ The TLD file is an XML-style document that defines a tag
library and its individual tags
¤ For each tag, it defines the tag name, its attributes, and the
name of the class that handles tag semantics
35
Writing Views:
JSP Tag Libraries
¤ JSP pages are an integral part of the Struts Framework
¤ Struts provides its own set of custom tag libraries
36
Tag library descriptor Purpose
struts-html.tld JSP tag extension for
HTML forms
struts-bean.tld JSP tag extension for
handling JavaBeans
struts-logic.tld JSP tag extension for
testing the values of
properties
Writing Views
login.jsp
<%@ taglib uri=”http://struts.apache.org/tags-html" prefix="html" %>
<html>
<head>
<title>Sign in, Please!</title>
</head>
<body>
<html:form action="/login" focus="username">
Username: <html:text property="username"/> <br/>
Password: <html:password property="password"/><br/>
<html:submit/> <html:reset/>
</html:form>
</body>
</html>
37
the taglib directive
makes accessible the
tag library to the JSP
page
JSP tag from the
struts-html tag
library
References
¤ Struts 1 In Action, T. N. Husted, C. Dumoulin, G. Franciscus,
D. Winterfeldt, , Manning Publications Co.
¤ JavaBeans, In Wikipedia, The Free
Encyclopedia,http://en.wikipedia.org/w/index.php?title=
JavaBeans&oldid=530069922
¤ JavaServer Pages, In Wikipedia, The Free
Encyclopediahttp://en.wikipedia.org/w/index.php?title=
JavaServer_Pages&oldid=528080552
38

More Related Content

What's hot

ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
Auwal Amshi
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel framework
Ahmad Fatoni
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Pravin Pundge
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
07.pallav
 
Servlets
ServletsServlets
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
Edureka!
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Emprovise
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)
Helder da Rocha
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Kasun Madusanke
 
11 Java Script - Exemplos com eventos
11 Java Script - Exemplos com eventos11 Java Script - Exemplos com eventos
11 Java Script - Exemplos com eventos
Centro Paula Souza
 
React - Introdução
React - IntroduçãoReact - Introdução
React - Introdução
Jefferson Mariano de Souza
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
Tanmoy Barman
 
Struts,Jsp,Servlet
Struts,Jsp,ServletStruts,Jsp,Servlet
Struts,Jsp,Servlet
dasguptahirak
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
IndicThreads
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding REST
Nitin Pande
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Harshit Choudhary
 

What's hot (20)

ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel framework
 
Servlets
ServletsServlets
Servlets
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Servlets
ServletsServlets
Servlets
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Spring MVC 3.0 Framework
 
Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
11 Java Script - Exemplos com eventos
11 Java Script - Exemplos com eventos11 Java Script - Exemplos com eventos
11 Java Script - Exemplos com eventos
 
React - Introdução
React - IntroduçãoReact - Introdução
React - Introdução
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Struts,Jsp,Servlet
Struts,Jsp,ServletStruts,Jsp,Servlet
Struts,Jsp,Servlet
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding REST
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 

Similar to Introduction to Struts 1.3

Asp.Net Mvc
Asp.Net MvcAsp.Net Mvc
Asp.Net Mvc
micham
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
People Strategists
 
Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desai
jinaldesailive
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
Tomi Juhola
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
Hùng Nguyễn Huy
 
Struts Interceptors
Struts InterceptorsStruts Interceptors
Struts Interceptors
Onkar Deshpande
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
John Lewis
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
nagarajupatangay
 
Struts course material
Struts course materialStruts course material
Struts course material
Vibrant Technologies & Computers
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Strutsyesprakash
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
Prashant Kumar
 
Unit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxUnit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptx
AbhijayKulshrestha1
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
erdemergin
 
MVC 6 Introduction
MVC 6 IntroductionMVC 6 Introduction
MVC 6 Introduction
Sudhakar Sharma
 
Asp.net,mvc
Asp.net,mvcAsp.net,mvc
Asp.net,mvc
Prashant Kumar
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnan
Gigin Krishnan
 
Struts 1
Struts 1Struts 1
Struts 1
Lalit Garg
 

Similar to Introduction to Struts 1.3 (20)

Asp.Net Mvc
Asp.Net MvcAsp.Net Mvc
Asp.Net Mvc
 
MVC
MVCMVC
MVC
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
 
Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desai
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Struts Interceptors
Struts InterceptorsStruts Interceptors
Struts Interceptors
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
 
Struts course material
Struts course materialStruts course material
Struts course material
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Struts
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
 
Unit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxUnit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptx
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
MVC 6 Introduction
MVC 6 IntroductionMVC 6 Introduction
MVC 6 Introduction
 
Asp.net,mvc
Asp.net,mvcAsp.net,mvc
Asp.net,mvc
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnan
 
Struts 1
Struts 1Struts 1
Struts 1
 

More from Ilio Catallo

C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
Ilio Catallo
 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++
Ilio Catallo
 
Resource wrappers in C++
Resource wrappers in C++Resource wrappers in C++
Resource wrappers in C++
Ilio Catallo
 
Memory management in C++
Memory management in C++Memory management in C++
Memory management in C++
Ilio Catallo
 
Operator overloading in C++
Operator overloading in C++Operator overloading in C++
Operator overloading in C++
Ilio Catallo
 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++
Ilio Catallo
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
Ilio Catallo
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++
Ilio Catallo
 
Spring MVC - Wiring the different layers
Spring MVC -  Wiring the different layersSpring MVC -  Wiring the different layers
Spring MVC - Wiring the different layers
Ilio Catallo
 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platforms
Ilio Catallo
 
Spring MVC - Web Forms
Spring MVC  - Web FormsSpring MVC  - Web Forms
Spring MVC - Web Forms
Ilio Catallo
 
Spring MVC - The Basics
Spring MVC -  The BasicsSpring MVC -  The Basics
Spring MVC - The Basics
Ilio Catallo
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
Ilio Catallo
 
Introduction To Spring
Introduction To SpringIntroduction To Spring
Introduction To Spring
Ilio Catallo
 
Gestione della memoria in C++
Gestione della memoria in C++Gestione della memoria in C++
Gestione della memoria in C++
Ilio Catallo
 
Array in C++
Array in C++Array in C++
Array in C++
Ilio Catallo
 
Puntatori e Riferimenti
Puntatori e RiferimentiPuntatori e Riferimenti
Puntatori e Riferimenti
Ilio Catallo
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
Ilio Catallo
 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag Library
Ilio Catallo
 
Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3
Ilio Catallo
 

More from Ilio Catallo (20)

C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++
 
Resource wrappers in C++
Resource wrappers in C++Resource wrappers in C++
Resource wrappers in C++
 
Memory management in C++
Memory management in C++Memory management in C++
Memory management in C++
 
Operator overloading in C++
Operator overloading in C++Operator overloading in C++
Operator overloading in C++
 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++
 
Spring MVC - Wiring the different layers
Spring MVC -  Wiring the different layersSpring MVC -  Wiring the different layers
Spring MVC - Wiring the different layers
 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platforms
 
Spring MVC - Web Forms
Spring MVC  - Web FormsSpring MVC  - Web Forms
Spring MVC - Web Forms
 
Spring MVC - The Basics
Spring MVC -  The BasicsSpring MVC -  The Basics
Spring MVC - The Basics
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
 
Introduction To Spring
Introduction To SpringIntroduction To Spring
Introduction To Spring
 
Gestione della memoria in C++
Gestione della memoria in C++Gestione della memoria in C++
Gestione della memoria in C++
 
Array in C++
Array in C++Array in C++
Array in C++
 
Puntatori e Riferimenti
Puntatori e RiferimentiPuntatori e Riferimenti
Puntatori e Riferimenti
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag Library
 
Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3
 

Recently uploaded

Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 

Recently uploaded (20)

Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 

Introduction to Struts 1.3

  • 1. Introduction to Jakarta Struts 1.3 Ilio Catallo – info@iliocatallo.it
  • 2. Outline ¤ Model-View-Controller vs. Web applications ¤ From MVC to MVC2 ¤ What is Struts? ¤ Struts Architecture ¤ Building web applications with Struts ¤ Setting up the Controller ¤ Writing Views ¤ References 2
  • 4. Model-View-Controller design pattern ¤ In the late seventies, software architects saw applications as having three major parts: ¤ The part that manages the data (Model) ¤ The part that creates screens and reports (View) ¤ The part that handles interactions between the user and the other subsystems (Controller) ¤ MVC turned out to be a good way to design applications ¤ Cocoa (Apple) ¤ Swing (Java) ¤ .NET (Microsoft) 4
  • 6. Model-View-Controller vs. Web applications ¤ What is the reason not to use the same MVC pattern also for web applications? ¤ Java developers already have utilities for: ¤ building presentation pages, e.g., JavaServer Pages (View) ¤ handling databases, e.g., JDBC and EJB (Model) ¤ But… ¤ the HTTP protocol imposes limitations on the applicability of the MVC design pattern ¤ we don’t have any component to act as the Controller 6
  • 7. HTTP limitations ¤ The MVC design pattern requires a push protocol for the views to be notified by the model ¤ HTTP is a pull protocol: no request implies no response ¤ The MVC design pattern requires a stateful protocol to keep track of the state of the application ¤ HTTP is stateless 7
  • 8. HTTP limitations: Struts solutions ¤ HTTP is stateless: we can implement the MVC design pattern on top of the Java Servlet Platform ¤ the platform provides a session context to help track users in the application ¤ HTTP is a pull protocol: we can increase the Controller responsibility. It will be responsible for: ¤ state changes ¤ state queries ¤ change notifications 8
  • 9. Model-View-Controller 2 design pattern ¤ The resulting design pattern is sometimes called MVC2 or Web MVC ¤ Any state query or change notification must pass through the Controller ¤ The View renders data passed by the Controller rather than data returned directly from the Model 9 View Controller Model
  • 10. What is Jakarta Struts? ¤ Jakarta Struts is an open source framework ¤ It provides a MVC2-style Controller that helps turn raw materials like web pages and databases into a coherent application ¤ The framework is based on a set of enabling technologies common to every Java web application: ¤ Java Servlets for implementing the Controller ¤ JavaServer Pages for implementing the View ¤ EJB or JDBC for implementing the Model 10
  • 12. Struts Main Components: ActionForward, ActionForm, Action ¤ Each web application is made of three main components: ¤ Hyperlinks lead to pages that display data and other elements, such as text and images ¤ HTML forms are used to submit data to the application ¤ Server-side actions which performs some kind of business logic on the data 12
  • 13. Struts Main Components: ActionForward, ActionForm, Action ¤ Struts provides components that programmers can use to define hyperlinks, forms and custom actions: ¤ Hyperlinks are represented as ActionForward objects ¤ Forms are represented as ActionForm objects ¤ Custom actions are represented as Action objects 13
  • 14. Struts Main Components: ActionMapping ¤ Struts bundles these details together into an ActionMapping object ¤ Each ActionMappinghas its own URI ¤ When a specific resource is requested by URI, the Controller retrieves the corresponding ActionMapping object ¤ The mapping tells the Controller which Action, ActionForm and ActionForwards to use 14
  • 15. Struts Main Components: ActionServlet ¤ The backbone component of the Struts framework is ActionServlet (i.e., the Struts Controller) ¤ For every request, the ActionServlet: ¤ uses the URI to understand which ActionMapping to use ¤ bundles all the user input into an ActionForm ¤ call the Action in charge of handling the request ¤ reads the ActionForwardcoming from the Action and forward the request to the JSP page what will render the result 15
  • 16. Struts Control Flow 16 Controller (ActionServlet) Action (ActionMapping, ActionForm) JSP page (with HTML form) JSP page (result page) HTTP request HTTP response ① ② ③ ④ Model (e.g., EJB) ActionForward ⑤ Controller Model
  • 17. Struts main component responsibilities Class Description ActionForward A user’s gesture or view selection ActionForm The data for a state change ActionMapping The state change event ActionServlet The part of the Controller that receives user gestures and stare changes and issues view selections Action classes The part of the Controller that interacts with the model to execute a state change or query and advises ActionServlet of the next view to select 17
  • 18. Building Web applications with Struts Setting up the Controller 18
  • 19. Setting up the Controller: The big picture 19 struts- config.xml web.xml ActionMapping 1 ActionMapping N
  • 20. Setting up the Controller: Servlet Container (1/3) ¤ The web.xml deployment descriptor file describes how to deploy a web application in a servlet container (e.g., Tomcat) ¤ The container reads the deployment descriptor web.xml, which specifies: ¤ which servlets to load ¤ which requests are sent to which servlet 20
  • 21. Setting up the Controller: Servlet Container (2/3) ¤ Struts implements the Controller as a servlet ¤ Like all servlets it lives in the servlet container ¤ Conventionally, the container is configured to sent to ActionServlet any request that matches the pattern *.do ¤ Remember: Any valid extension or prefix can be used, .do is simply a popular choice 21
  • 22. Setting up the Controller: Servlet Container (3/3) web.xml (snippet) <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> 22 ¤ Forward any request that matches the pattern *.do to the servlet named action (i.e., the Struts controller)
  • 23. Struts Controller: struts-config.xml ¤ The framework uses the struts-config.xml file as a deployment descriptor ¤ It contains all the ActionMappings definedfor the web application ¤ At boot time, Struts reads it to create a database of objects ¤ At runtime, Struts refers to the object created with the configuration file, not the file itself 23
  • 24. Struts Controller: ActionForm (1/4) ¤ A JavaBean is a reusable software component which conform to a set of design patterns ¤ The access to the bean’s internal state is provided through two kinds of methods: accessors and mutators ¤ JavaBeans are used to encapsulate many objects into a single object ¤ They can be passed around as a single bean object instead of as multiple individual objects 24
  • 25. Struts Controller: ActionForm (2/4) ¤ Struts model ActionForms as JavaBeans ¤ The ActionForm has a corresponding property for each field on the HTML form ¤ The Controller matches the parameters in the HTTP request with the properties of the ActionForm ¤ When they correspond, the Controller calls the setter methods and passes the value from the HTTP request 25
  • 26. Struts Controller: ActionForm (3/4) LoginForm.java pubic class LoginForm extends org.apache.struts.action.ActionForm { private String username; private String password; public String getUsername() {return this.username;} public String getPassword() {return this.password;} public void setUsername(String username) {this.username = username;} public void setPassword(String password) {this.password = password;} } 26 ¤ An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm
  • 27. Struts Controller: ActionForm (4/4) Specifying a new ActionForm in struts-config.xml <form-beans> <form-bean name=”loginForm" type=”app.LoginForm"/> </form-beans> 27 ¤ Define a mapping between the actual ActionForm and its logical name
  • 28. Struts Controller: ActionForwards Specifying new ActionForwardsin struts-config.xml <forward name="success" path="/success.html"/> <forward name=”failure" path="/success.html"/> <forward name=”logon" path=”/Logon.do"/> 28 ¤ Define a mapping between the resource link and its logical name ¤ Once defined, throughout the web application it is possible to reference the resource via its logical name
  • 29. Struts Controller: Action ¤ Actions are Java classes that extend org.apache.struts.Action ¤ The Controller populates the ActionForm and then passes it to the Action ¤ the entry method is perform (Struts 1.0) or execute (Struts 1.1+) ¤ The Action is generally responsible for: ¤ validating input ¤ accessing business information ¤ determining which ActionForward to return to the Controller 29
  • 30. Struts Controller: Action LoginAction.java import javax.servet.http.*; public class LoginAction extends org.apache.struts.action.Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) { // Extract data from the form LoginForm lf = (LoginForm) form; String username = lf.getUsername(); String password = lf.getPassword(); // Apply business logic UserDirectory ud = UserDirectory.getInstance(); if (ud.isValidPassword(username, password)) return mapping.findForward("success"); return mapping.findForward("failure"); } } 30
  • 31. Struts Controller: struts-config.xml struts-config.xml (snippet) <form-beans> <form-bean name="loginForm" type="app.LoginForm"/> </form-beans> <action-mappings> <action path="/login" type="app.LoginAction" name="loginForm"> <forward name="success" path="/success.jsp"/> <forward name="failure" path="/failure.jsp"/> </action> </action-mappings> 31 Struts trims automatically the .do extension
  • 32. Building web applications with Struts Writing Views 32
  • 33. Writing Views: JavaServer Pages (JSP) ¤ JavaServer Pages is a technology that helps Java developers create dynamically generated web pages ¤ A JSP page is a mix of plain old HTML tags and JSP scripting elements ¤ JSP pages are translated into servlets at runtime by the JSP container 33 JSP Scripting Element <b> This page was accessed at <%= new Date() %></b>
  • 34. Writing Views: JSP tags ¤ JSP scripting elements require that developers mix Java code with HTML. This situation leads to: ¤ non-maintainable applications ¤ no opportunity for code reuse ¤ An alternative to scripting elements is to use JSP tags ¤ JSP tags can be used as if they were ordinary HTML tags ¤ Each JSP tag is associated with a Java class ¤ It’s sufficient to insert the same tag on another page to reuse the same code ¤ If the code changes, all the pages are automatically updated 34
  • 35. Writing Views: JSP Tag Libraries ¤ A number of prebuilt tag libraries are available for developers ¤ Example: JSP Standard Tag Library (JSTL) ¤ Each JSP tag library is associated with a Tag Library Descriptor (TLD) ¤ The TLD file is an XML-style document that defines a tag library and its individual tags ¤ For each tag, it defines the tag name, its attributes, and the name of the class that handles tag semantics 35
  • 36. Writing Views: JSP Tag Libraries ¤ JSP pages are an integral part of the Struts Framework ¤ Struts provides its own set of custom tag libraries 36 Tag library descriptor Purpose struts-html.tld JSP tag extension for HTML forms struts-bean.tld JSP tag extension for handling JavaBeans struts-logic.tld JSP tag extension for testing the values of properties
  • 37. Writing Views login.jsp <%@ taglib uri=”http://struts.apache.org/tags-html" prefix="html" %> <html> <head> <title>Sign in, Please!</title> </head> <body> <html:form action="/login" focus="username"> Username: <html:text property="username"/> <br/> Password: <html:password property="password"/><br/> <html:submit/> <html:reset/> </html:form> </body> </html> 37 the taglib directive makes accessible the tag library to the JSP page JSP tag from the struts-html tag library
  • 38. References ¤ Struts 1 In Action, T. N. Husted, C. Dumoulin, G. Franciscus, D. Winterfeldt, , Manning Publications Co. ¤ JavaBeans, In Wikipedia, The Free Encyclopedia,http://en.wikipedia.org/w/index.php?title= JavaBeans&oldid=530069922 ¤ JavaServer Pages, In Wikipedia, The Free Encyclopediahttp://en.wikipedia.org/w/index.php?title= JavaServer_Pages&oldid=528080552 38