SlideShare a Scribd company logo
1 of 86
1
Struts 2.x
Agenda
 Struts Introduction
 Struts Web Flow
 Struts Architecture
 Struts Basic Example
 Dynamic Method Invocation
 Multiple Struts.xml files
 IOC and DI
 Interceptors
 Validation
 Internationalization
 Control Tags
 Struts2 with Jquery
 Build in Interceptor
 Custom Interceptor
 I18N
Struts2 is a free Open Source Framework
Apache Struts2 was originally known as WebWork 2. After working independently
for several years, the WebWork and Struts communities joined forces to create
Struts2.
It is based on MVC2 Architecture
In Struts 2 FilterDispatcher does the job of Controller.
Model contains the data and the business logic.
In Struts 2 the model is implemented by the Action component.
View is the presentation component of the MVC Pattern.
In Struts 2 View is implemented by JSP
Struts 2 is a pull-MVC framework. i.e. the data that is to be displayed to user has to
be pulled from the Action.
The “pull” comes from the views ability to pull data from an action using Value
Stack/OGNL.
Struts 2 Action class are plain POJO objects thus simplifying the testing of the code.
Struts Introduction
What is MVC ?
Servlet
(Controller)
Servlet
(Controller)
1. Get Request parameters
Business Service
(Model)
Business Service
(Model)
2. Call Business Service
DBDB
Business Service talk to DB
JSP
(View)
JSP
(View)
3. Pass the result to the JSP
4. Return Formatted HTML
MVC
Why MVC
1. Business Logic (Model) is separate from controller.
2. View is separate from Controller
3. View is separate from Model
Conclusion : MVC Follows Separation of Concern Principal.
MVC Framework
1. It provide pre-build classes
2. It is a collections of Base classes and Jars
3. They are Extensible
4. Popular Java MVC are
Struts 1.x , Struts 2.x , JSF , Wicket , Spring MVC, Play, Grails
Framework vs Pattern
1. Pattern is the way you can architect your application.
2. Framework provides foundation (base) classes and
libraries.
3. Leverage industry best practices.
Struts 2 Web FlowStruts MVC Flow
Five Core Components:
1. Actions
 The most basic unit of work that can be associated with a HTTP request coming from a user.
2. Interceptors
 They provide a way to supply pre-processing and post-processing around the action. They have access to
the action being executed, as well as all environmental variables and execution properties.
 Interceptors are conceptually the same as servlet filters, can be layered and ordered.
3. Value stack / OGNL.
 The value stack is exactly what it says it is – a stack of objects. OGNL stands for Object Graph
Navigational Language, and provides the unified way to access objects within the value stack.
4. Result types
 Chain, Dispatcher, Freemarker, HttpHeader, Redirect, Redirect-Action, Stream, Velocity, XSLT.
 If the attribute is not supplied, the default type “dispatcher” is used – this will render a JSP result.
5. View technologies.
 JSP
 Velocity Templates
 Free marker Templates
 XSLT Transformations
Struts 2 Core Components
Architecture of Struts 2
Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE
technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its
architecture.
It is optional Filter
, and it is used to
integrate the Struts
with SiteMesh Plugin
Struts Architecture
Architecture of Struts 2
Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE
technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its
architecture.
SiteMesh is a web-page
layout and decoration
framework and web
application integration
framework to aid in
creating large sites
consisting of many
pages for which a
consistent look/feel,
navigation and layout
scheme is required.
Struts Architecture
Architecture of Struts 2
Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE
technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its
architecture.
The FilterDispatcher filter is
called which consults the
ActionMapper to determine
whether an Action should
be invoked
Struts Architecture
Architecture of Struts 2
Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE
technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its
architecture.
If ActionMapper finds an Action
to be invoked, the FilterDispatcher
delegates control to ActionProxy.
Struts Architecture
Architecture of Struts 2
Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE
technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its
architecture.
tionProxy reads the configuration
e such as struts.xml.
tionProxy creates an instance
ActionInvocation class and
legates the control.
Struts Architecture
Architecture of Struts 2
Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE
technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its
architecture.
onInvocation is responsible
nvokes the Interceptors one by
(if required) and then invoke
Action.
Struts Architecture
Architecture of Struts 2
Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE
technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its
architecture.
Once the Action returns, the
ActionInvocation is
esponsible for looking up
the proper result associated
with the Action result code
mapped in struts.xml.
Struts Architecture
Architecture of Struts 2
Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE
technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its
architecture.
Interceptors are executed
ain in reverse order and the
onse is returned to the Filter
most cases to FilterDispatcher).
the result is then sent to the
let container which in turns
d it back to client
Struts Architecture
Develop Struts First Application
Struts Basic Example
Struts First Program
For Creating Struts First Program, You required the Following things
a) JDK 1.5 or Higher
b) Servlet API and JSP API
c) J2EE Compliance Web Server or Application Server
d) Download the Following Jar Files from http://struts.apache.org/download.cgi
Add the Library in the Deployment Assembly
Step -1 Struts Filter Entry in web.xml
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Step -2 Create an Action Class
Step -3 Create a View
Step -4 Create struts.xml File
Struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="actionDemo"
class="com.srivastava.demo.ActionDemo" method="execute">
<result name="success">/welcome.jsp</result>
</action>
</package>
</struts>
Output
Login Page Demo
Login.jsp
LoginAction
Success
error
Step-1 Create Login.jsp
Step-2 Create LoginAction
Step-3 Create Welcome.jsp
Step-4 Create error.jsp
Step-5 Create struts.xml
Struts 1.x v/s Struts 2.x
Feature Struts 1.x Struts 2.x
Action
Classes
Struts 1 requires Action
classes to extend an
abstract base class. A
common problem in
Struts 1 is programming
to abstract classes
instead of interfaces.
An Struts 2 Action may implement
an Action interface, along with
other interfaces to enable optional
and custom services. Struts 2
provides a base ActionSupport class
to implement commonly used
interfaces. Albeit, the Action
interface is not required. Any POJO
object with a execute signature can
be used as an Struts 2 Action
object.
Binding
Values
into
views
To access different
objects , struts 1 uses
the standard jsp implict
objects
It use valuestack to hold the values
and to reterive the value from value
stack it use OGNL (Object Graph
Navigational Language)
Servlet
Depende
ncy
In action execute
method , it has
HttpServletRequest and
HttpServletResponse
Object, both comes from
servlet API
Not needed in struts 2 execute
method
Testablit A major hurdle to Struts 2 Actions can be tested by
Multiple Struts.xml File
We can include other struts.xml-format files from a bootstrap struts.xml file
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file=“advice.xml"/>
<include file=“contract.xml"/>
<include file=“dms.xml"/>
</struts>
Dynamic Method Invocation
Dynamic Method Invocation
Dynamic Method Invocation
UI in Struts 2
Designing UI in Struts 2
The form Tag
Eg.
<s:form action=“actionname” method =“post”>
</s:form>
The textfield tag
<s:textfield name=“userid” label =“userid” />
The TextArea tag
<s:textarea name=“address” label=“Address” cols=“15” rows=“2” />
UI
The password tag
<s:password name=“password” label=“Password” />
The Checkbox Tag
<s:checkbox name=“cricket” label=“Cricket” fieldValue=“C”/>
<s:checkbox name=“hockey” label=“Hockey” fieldValue=“H”/>
The Radio Tag
<s:radio name=“m_status” label=“Marital Status” list=“{‘Single’,’Married’}” />
The Hidden Tag
<s:hidden name=“empid” value=“Some Value” />
UI
The Combo box
<s:combobox label=“Country" headerKey="-1" headerValue="--- Select ---" list=“country"
name=“country" />
class Action extends ActionSupport
{
private List<String> country;
public void setCountry(List<String> country) { }
public List<String> getCountryList() { }
}
The submit tag
<s:submit/>
The datetimepicker tag
<s:datetimepicker name=“dob” label =“Date of Birth” displayFormat="dd MMMM,
yyyy" />
UI
Using Freemarker template for Creating Custom UI
FreeMarker is a "template engine"; a generic tool to generate text output
To Print the Values in FTL
Welcome ${user}
If condition in FTL
<#if field.formatType??>
</#if>
Loops in FTL
<#list tabList as page>
</#list>
Freemarker
Creating Own Components Using FTL
Eg. Creating Password Field Using FTL
<input type="password" <#rt/>
name="${parameters.name?default("")?html}"<#rt/>
<#if parameters.get("size")??>
size="${parameters.get("size")?html}"<#rt/>
</#if>
<#if parameters.maxlength??>
maxlength="${parameters.maxlength?html}"<#rt/>
</#if>
<#if parameters.id??>
id="${parameters.id?html}"<#rt/>
</#if>
<#if parameters.get("size")??>
size="${parameters.get("size")?html}"<#rt/>
</#if>
<#if parameters.onblur??>
onblur="${parameters.onblur?html}"<#rt/>
</#if>
/>
NOTE: Store your FTL File in public-html template finnonepro
Freemarker
Calling FTL using <s:component tag> , place in JSP File
<s:component template="password.ftl" theme="finnonepro" id="28000005"
name="FW_SC_PW_OodPW">
<s:param name="maxlength" value="'20'"/>
<s:param name="size" value="'12'"/>
<s:param name="mandatory" value="'Y'"/>
</s:component>
Freemarker
IOC (Inversion of Control) and DI (Dependency Injection)
IOC and DI are programming design patterns, which are used to reduce coupling in
programming.
It follow the Following Principle:
a) You do not need to create your objects. You need to only describe how they should
be created. (This think is done by ObjectFactory)
To enable the IOC in Struts
a) Using an Enabler Interface
Eg. SessionAware, ApplicationAware etc.
IOC (Inversion of Control)
IOC (Inversion of Control)
Exercise:
Create an Online Shopping Application, where user can login and register if the User is
New. Once User login in the System , the Application display the items to the User , so
User can choose it and buy the desire item. The Selected Item has the given features like
Item Name , Size , Color , Quantity and Price.
Once the User buy the selected item , the final bill is generated and display to the User
Interceptor
Interceptor is used for seperation of core functionality code in the form of
Interceptors makes Action more lightweight.
The purpose of Interceptors is to allow greater control over controller layer and
separate some common logic that applies to multiple actions.
All framework interceptors defined in struts-default.xml
Interceptors
Alias Interceptor
Alias Interceptor
This interceptor alias a named parameter to a different parameter name.
Suppose your jsp having two textfield name t1 and t2 and in your action class you defined t3
and t4 variable , so alias interceptor can map t1 with t3 alias and t2 with t4 alias.
Step-1 Create JSP File
Step-2 Create Action Class
Step-3 Entry in Struts.xml File
Step-4 ApplicationResource File
Step-5 struts.properties
ExecuteAndWait Interceptor
While running a long action, the user may get impatient in case of a long delay in
response. To avoid this, the execAndWait Interceptor is used, which runs a long
running action in the background and display a page with a Loading to the user.
Step -1 Create JSP
Step -2 Create Action
Step -3 Create Wait.jsp
Step -4 Create struts.xml
an initial delay
in millis to wait
before the wait page is shown
Used for waking up at
certain intervals to check
if the background process is
already done. Default is
100 millis
Exception Interceptor
The Struts 2 framework provides the functionality of exception handling through the
Interceptor. Instead of displaying stack trace for the exception to the user, it is always
good to show a nicely designed page describing the real problem to the user.
Step -1 Create JSP
Step -2 Create Action Class
Step -3 Struts.xml
Step -4 exception jsp file
Creating Own Interceptor
This framework provides the flexibility to create own interceptor classes to enable
additional logic which can be separated and refused in the Interceptor stack of different
action classes.
The Custom interceptor class need to be defined in the struts.xml file.
Step -1 Create Interceptor Java File
Step -2 Entry in struts.xml file
Validation Framework
Struts 2 based on a validation framework, which is provided by Xwork.
The Validation framework uses external metadata in the form of XML files to describe
what validation should be performed on your action.
Struts2 Validation Framework allows us to separate the validation logic from actual
Java/JSP code, where it can be reviewed and easily modified later.
Validation can be perform
a) Programmatic
b) XML Meta Data
Validation Framework
Validation Using XML Meta-Data
Step -1 Create JSP
Step -2 Create Action Class
Step -3 create validation.xml file
Step -3 create validation.xml file
Step -4 struts.xml
Note: validation.xml file placed in the same location , where Action is placed and it
is same name as action name and end with validation.xml file
Programmatic Validation
It is written in the Actionclass by overriding the
validate method , this method calls automatically
when user submit the page, it is call before the
execute method , and if any error occurred , it return
the “input” as a result , otherwise it execute the
execute method of the action
Step -1 Create an Action
Override the validate method
it comes from Validateable
interface, which is
implemented by
ActionSupport class
Internationalization
Internationalization is a technique for application development that support multiple
languages and data formats without having to rewrite programming logic.
Create different languages
application resource property file’s
and these files name end
with country language code
Note: Also Specify the application resource name and path in
struts.properties file, the path is required if you are not placed in
application resoource file in the src folder
Application Resource File
Entry in struts.properties
Create JSP File
Changing Browser Language
1 2
3
Control Tags
<s:if>
<s:iterator>
Control Tags
Control Tags
Thank You !

More Related Content

What's hot

Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture ComponentsBurhanuddinRashid
 
Rapid development tools for java ee 8 [tut2998]
Rapid development tools for java ee 8 [tut2998]Rapid development tools for java ee 8 [tut2998]
Rapid development tools for java ee 8 [tut2998]Payara
 
Struts 2 And Spring Frameworks Together
Struts 2 And Spring Frameworks TogetherStruts 2 And Spring Frameworks Together
Struts 2 And Spring Frameworks TogetherSyed Shahul
 
JPA lifecycle events practice
JPA lifecycle events practiceJPA lifecycle events practice
JPA lifecycle events practiceGuo Albert
 
Rapid Development Tools for Java EE 8 [TUT2998]
Rapid Development Tools for Java EE 8 [TUT2998]Rapid Development Tools for Java EE 8 [TUT2998]
Rapid Development Tools for Java EE 8 [TUT2998]Gaurav Gupta
 
JavaEE 8 on a diet with Payara Micro 5
JavaEE 8 on a diet with Payara Micro 5JavaEE 8 on a diet with Payara Micro 5
JavaEE 8 on a diet with Payara Micro 5Payara
 
JSUG - Google Guice by Jan Zarnikov
JSUG - Google Guice by Jan ZarnikovJSUG - Google Guice by Jan Zarnikov
JSUG - Google Guice by Jan ZarnikovChristoph Pickl
 
Architecture Components
Architecture Components Architecture Components
Architecture Components DataArt
 
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6Saltmarch Media
 
Advanced Hibernate Notes
Advanced Hibernate NotesAdvanced Hibernate Notes
Advanced Hibernate NotesKaniska Mandal
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern11prasoon
 
Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 javatwo2011
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracleyazidds2
 
Cocoa Design Patterns
Cocoa Design PatternsCocoa Design Patterns
Cocoa Design Patternssgleadow
 

What's hot (19)

Drools
DroolsDrools
Drools
 
Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture Components
 
04 Data Access
04 Data Access04 Data Access
04 Data Access
 
Rapid development tools for java ee 8 [tut2998]
Rapid development tools for java ee 8 [tut2998]Rapid development tools for java ee 8 [tut2998]
Rapid development tools for java ee 8 [tut2998]
 
Struts 2 And Spring Frameworks Together
Struts 2 And Spring Frameworks TogetherStruts 2 And Spring Frameworks Together
Struts 2 And Spring Frameworks Together
 
JPA lifecycle events practice
JPA lifecycle events practiceJPA lifecycle events practice
JPA lifecycle events practice
 
Rapid Development Tools for Java EE 8 [TUT2998]
Rapid Development Tools for Java EE 8 [TUT2998]Rapid Development Tools for Java EE 8 [TUT2998]
Rapid Development Tools for Java EE 8 [TUT2998]
 
JavaEE 8 on a diet with Payara Micro 5
JavaEE 8 on a diet with Payara Micro 5JavaEE 8 on a diet with Payara Micro 5
JavaEE 8 on a diet with Payara Micro 5
 
JSUG - Google Guice by Jan Zarnikov
JSUG - Google Guice by Jan ZarnikovJSUG - Google Guice by Jan Zarnikov
JSUG - Google Guice by Jan Zarnikov
 
Architecture Components
Architecture Components Architecture Components
Architecture Components
 
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
 
Advanced Hibernate Notes
Advanced Hibernate NotesAdvanced Hibernate Notes
Advanced Hibernate Notes
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
 
Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
 
Data access
Data accessData access
Data access
 
Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
Cocoa Design Patterns
Cocoa Design PatternsCocoa Design Patterns
Cocoa Design Patterns
 
JPA For Beginner's
JPA For Beginner'sJPA For Beginner's
JPA For Beginner's
 

Viewers also liked

CCHHS HR Recruitment Infographic
CCHHS HR Recruitment InfographicCCHHS HR Recruitment Infographic
CCHHS HR Recruitment InfographicLisa Capozzi
 
Making your own bootloader
Making your own bootloaderMaking your own bootloader
Making your own bootloaderiamumr
 
It cloud services
It cloud servicesIt cloud services
It cloud serviceszumoku
 
Ordin MAI nr.-195-din- 2007 criterii SVSU
Ordin MAI  nr.-195-din- 2007 criterii SVSUOrdin MAI  nr.-195-din- 2007 criterii SVSU
Ordin MAI nr.-195-din- 2007 criterii SVSUomirel
 
Ordin MIRA195 svsu criterii svsu si spsu
Ordin MIRA195 svsu criterii svsu si spsuOrdin MIRA195 svsu criterii svsu si spsu
Ordin MIRA195 svsu criterii svsu si spsuomirel
 
Soccer for peace
Soccer for peaceSoccer for peace
Soccer for peacesoccerpeace
 
Minor Presentation - Distributed file system
Minor Presentation - Distributed file systemMinor Presentation - Distributed file system
Minor Presentation - Distributed file systemiamumr
 
How to dive
How to diveHow to dive
How to divezumoku
 
Completed MSc TESOL dissertation_Xi ZHU
Completed MSc TESOL dissertation_Xi ZHUCompleted MSc TESOL dissertation_Xi ZHU
Completed MSc TESOL dissertation_Xi ZHUXi Zhu
 
Riscuri I.S.U. Timis
Riscuri I.S.U. TimisRiscuri I.S.U. Timis
Riscuri I.S.U. Timisomirel
 
Ordin mai 160 din_2007 planificare svsu
Ordin mai 160 din_2007 planificare svsuOrdin mai 160 din_2007 planificare svsu
Ordin mai 160 din_2007 planificare svsuomirel
 
Actify's Product solution Presentation in Simplified Chinese
Actify's Product solution Presentation in Simplified ChineseActify's Product solution Presentation in Simplified Chinese
Actify's Product solution Presentation in Simplified ChineseAlen Kuo
 
Repere cultural-educative - protectie civila
Repere cultural-educative -  protectie civilaRepere cultural-educative -  protectie civila
Repere cultural-educative - protectie civilaomirel
 
tf presentation
tf presentationtf presentation
tf presentationzumoku
 
GAME PLAN FOR 2017 GENERAL ELECTION MARCH-2015
GAME PLAN FOR 2017 GENERAL ELECTION MARCH-2015GAME PLAN FOR 2017 GENERAL ELECTION MARCH-2015
GAME PLAN FOR 2017 GENERAL ELECTION MARCH-2015samuel mutemi
 
Description and basics of lilo
Description and basics of liloDescription and basics of lilo
Description and basics of liloiamumr
 

Viewers also liked (20)

CCHHS HR Recruitment Infographic
CCHHS HR Recruitment InfographicCCHHS HR Recruitment Infographic
CCHHS HR Recruitment Infographic
 
00
0000
00
 
Making your own bootloader
Making your own bootloaderMaking your own bootloader
Making your own bootloader
 
It cloud services
It cloud servicesIt cloud services
It cloud services
 
Ordin MAI nr.-195-din- 2007 criterii SVSU
Ordin MAI  nr.-195-din- 2007 criterii SVSUOrdin MAI  nr.-195-din- 2007 criterii SVSU
Ordin MAI nr.-195-din- 2007 criterii SVSU
 
Ordin MIRA195 svsu criterii svsu si spsu
Ordin MIRA195 svsu criterii svsu si spsuOrdin MIRA195 svsu criterii svsu si spsu
Ordin MIRA195 svsu criterii svsu si spsu
 
Soccer for peace
Soccer for peaceSoccer for peace
Soccer for peace
 
Reglamento del aprendiz sena
Reglamento del aprendiz sena Reglamento del aprendiz sena
Reglamento del aprendiz sena
 
Minor Presentation - Distributed file system
Minor Presentation - Distributed file systemMinor Presentation - Distributed file system
Minor Presentation - Distributed file system
 
How to dive
How to diveHow to dive
How to dive
 
Completed MSc TESOL dissertation_Xi ZHU
Completed MSc TESOL dissertation_Xi ZHUCompleted MSc TESOL dissertation_Xi ZHU
Completed MSc TESOL dissertation_Xi ZHU
 
Riscuri I.S.U. Timis
Riscuri I.S.U. TimisRiscuri I.S.U. Timis
Riscuri I.S.U. Timis
 
Ordin mai 160 din_2007 planificare svsu
Ordin mai 160 din_2007 planificare svsuOrdin mai 160 din_2007 planificare svsu
Ordin mai 160 din_2007 planificare svsu
 
Actify's Product solution Presentation in Simplified Chinese
Actify's Product solution Presentation in Simplified ChineseActify's Product solution Presentation in Simplified Chinese
Actify's Product solution Presentation in Simplified Chinese
 
Eğiticinin Eğitimi Uygulama Sınavı Ör.
Eğiticinin Eğitimi Uygulama Sınavı Ör.Eğiticinin Eğitimi Uygulama Sınavı Ör.
Eğiticinin Eğitimi Uygulama Sınavı Ör.
 
Anika
AnikaAnika
Anika
 
Repere cultural-educative - protectie civila
Repere cultural-educative -  protectie civilaRepere cultural-educative -  protectie civila
Repere cultural-educative - protectie civila
 
tf presentation
tf presentationtf presentation
tf presentation
 
GAME PLAN FOR 2017 GENERAL ELECTION MARCH-2015
GAME PLAN FOR 2017 GENERAL ELECTION MARCH-2015GAME PLAN FOR 2017 GENERAL ELECTION MARCH-2015
GAME PLAN FOR 2017 GENERAL ELECTION MARCH-2015
 
Description and basics of lilo
Description and basics of liloDescription and basics of lilo
Description and basics of lilo
 

Similar to Struts2.x

Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questionsjbashask
 
Krazykoder struts2 intro
Krazykoder struts2 introKrazykoder struts2 intro
Krazykoder struts2 introKrazy Koder
 
important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questionssurendray
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Strutsyesprakash
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 FrameworkEmprovise
 
Struts 2 – Interceptors
Struts 2 – InterceptorsStruts 2 – Interceptors
Struts 2 – InterceptorsDucat India
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksSunil Patil
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworksSunil Patil
 

Similar to Struts2.x (20)

Struts
StrutsStruts
Struts
 
Struts2
Struts2Struts2
Struts2
 
Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questions
 
Krazykoder struts2 intro
Krazykoder struts2 introKrazykoder struts2 intro
Krazykoder struts2 intro
 
Struts ppt 1
Struts ppt 1Struts ppt 1
Struts ppt 1
 
Struts Interceptors
Struts InterceptorsStruts Interceptors
Struts Interceptors
 
Struts Basics
Struts BasicsStruts Basics
Struts Basics
 
Struts Ppt 1
Struts Ppt 1Struts Ppt 1
Struts Ppt 1
 
important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questions
 
Struts 1
Struts 1Struts 1
Struts 1
 
Struts
StrutsStruts
Struts
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Struts
 
141060753008 3715301
141060753008 3715301141060753008 3715301
141060753008 3715301
 
Struts2
Struts2Struts2
Struts2
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 Framework
 
Struts 2 – Interceptors
Struts 2 – InterceptorsStruts 2 – Interceptors
Struts 2 – Interceptors
 
Struts2 notes
Struts2 notesStruts2 notes
Struts2 notes
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source Frameworks
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
 
Lecture 05 web_applicationframeworks
Lecture 05 web_applicationframeworksLecture 05 web_applicationframeworks
Lecture 05 web_applicationframeworks
 

Recently uploaded

Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 

Struts2.x

  • 2. Agenda  Struts Introduction  Struts Web Flow  Struts Architecture  Struts Basic Example  Dynamic Method Invocation  Multiple Struts.xml files  IOC and DI  Interceptors  Validation  Internationalization  Control Tags  Struts2 with Jquery  Build in Interceptor  Custom Interceptor  I18N
  • 3. Struts2 is a free Open Source Framework Apache Struts2 was originally known as WebWork 2. After working independently for several years, the WebWork and Struts communities joined forces to create Struts2. It is based on MVC2 Architecture In Struts 2 FilterDispatcher does the job of Controller. Model contains the data and the business logic. In Struts 2 the model is implemented by the Action component. View is the presentation component of the MVC Pattern. In Struts 2 View is implemented by JSP Struts 2 is a pull-MVC framework. i.e. the data that is to be displayed to user has to be pulled from the Action. The “pull” comes from the views ability to pull data from an action using Value Stack/OGNL. Struts 2 Action class are plain POJO objects thus simplifying the testing of the code. Struts Introduction
  • 5. Servlet (Controller) Servlet (Controller) 1. Get Request parameters Business Service (Model) Business Service (Model) 2. Call Business Service DBDB Business Service talk to DB JSP (View) JSP (View) 3. Pass the result to the JSP 4. Return Formatted HTML MVC
  • 6. Why MVC 1. Business Logic (Model) is separate from controller. 2. View is separate from Controller 3. View is separate from Model Conclusion : MVC Follows Separation of Concern Principal.
  • 7. MVC Framework 1. It provide pre-build classes 2. It is a collections of Base classes and Jars 3. They are Extensible 4. Popular Java MVC are Struts 1.x , Struts 2.x , JSF , Wicket , Spring MVC, Play, Grails
  • 8. Framework vs Pattern 1. Pattern is the way you can architect your application. 2. Framework provides foundation (base) classes and libraries. 3. Leverage industry best practices.
  • 9. Struts 2 Web FlowStruts MVC Flow
  • 10. Five Core Components: 1. Actions  The most basic unit of work that can be associated with a HTTP request coming from a user. 2. Interceptors  They provide a way to supply pre-processing and post-processing around the action. They have access to the action being executed, as well as all environmental variables and execution properties.  Interceptors are conceptually the same as servlet filters, can be layered and ordered. 3. Value stack / OGNL.  The value stack is exactly what it says it is – a stack of objects. OGNL stands for Object Graph Navigational Language, and provides the unified way to access objects within the value stack. 4. Result types  Chain, Dispatcher, Freemarker, HttpHeader, Redirect, Redirect-Action, Stream, Velocity, XSLT.  If the attribute is not supplied, the default type “dispatcher” is used – this will render a JSP result. 5. View technologies.  JSP  Velocity Templates  Free marker Templates  XSLT Transformations Struts 2 Core Components
  • 11. Architecture of Struts 2 Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its architecture. It is optional Filter , and it is used to integrate the Struts with SiteMesh Plugin Struts Architecture
  • 12. Architecture of Struts 2 Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its architecture. SiteMesh is a web-page layout and decoration framework and web application integration framework to aid in creating large sites consisting of many pages for which a consistent look/feel, navigation and layout scheme is required. Struts Architecture
  • 13. Architecture of Struts 2 Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its architecture. The FilterDispatcher filter is called which consults the ActionMapper to determine whether an Action should be invoked Struts Architecture
  • 14. Architecture of Struts 2 Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its architecture. If ActionMapper finds an Action to be invoked, the FilterDispatcher delegates control to ActionProxy. Struts Architecture
  • 15. Architecture of Struts 2 Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its architecture. tionProxy reads the configuration e such as struts.xml. tionProxy creates an instance ActionInvocation class and legates the control. Struts Architecture
  • 16. Architecture of Struts 2 Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its architecture. onInvocation is responsible nvokes the Interceptors one by (if required) and then invoke Action. Struts Architecture
  • 17. Architecture of Struts 2 Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its architecture. Once the Action returns, the ActionInvocation is esponsible for looking up the proper result associated with the Action result code mapped in struts.xml. Struts Architecture
  • 18. Architecture of Struts 2 Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its architecture. Interceptors are executed ain in reverse order and the onse is returned to the Filter most cases to FilterDispatcher). the result is then sent to the let container which in turns d it back to client Struts Architecture
  • 19. Develop Struts First Application
  • 20. Struts Basic Example Struts First Program For Creating Struts First Program, You required the Following things a) JDK 1.5 or Higher b) Servlet API and JSP API c) J2EE Compliance Web Server or Application Server d) Download the Following Jar Files from http://struts.apache.org/download.cgi
  • 21. Add the Library in the Deployment Assembly
  • 22. Step -1 Struts Filter Entry in web.xml Web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
  • 23. Step -2 Create an Action Class
  • 24. Step -3 Create a View
  • 25. Step -4 Create struts.xml File Struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="default" extends="struts-default"> <action name="actionDemo" class="com.srivastava.demo.ActionDemo" method="execute"> <result name="success">/welcome.jsp</result> </action> </package> </struts>
  • 33. Struts 1.x v/s Struts 2.x Feature Struts 1.x Struts 2.x Action Classes Struts 1 requires Action classes to extend an abstract base class. A common problem in Struts 1 is programming to abstract classes instead of interfaces. An Struts 2 Action may implement an Action interface, along with other interfaces to enable optional and custom services. Struts 2 provides a base ActionSupport class to implement commonly used interfaces. Albeit, the Action interface is not required. Any POJO object with a execute signature can be used as an Struts 2 Action object. Binding Values into views To access different objects , struts 1 uses the standard jsp implict objects It use valuestack to hold the values and to reterive the value from value stack it use OGNL (Object Graph Navigational Language) Servlet Depende ncy In action execute method , it has HttpServletRequest and HttpServletResponse Object, both comes from servlet API Not needed in struts 2 execute method Testablit A major hurdle to Struts 2 Actions can be tested by
  • 34. Multiple Struts.xml File We can include other struts.xml-format files from a bootstrap struts.xml file <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <include file=“advice.xml"/> <include file=“contract.xml"/> <include file=“dms.xml"/> </struts>
  • 39. Designing UI in Struts 2 The form Tag Eg. <s:form action=“actionname” method =“post”> </s:form> The textfield tag <s:textfield name=“userid” label =“userid” /> The TextArea tag <s:textarea name=“address” label=“Address” cols=“15” rows=“2” /> UI
  • 40. The password tag <s:password name=“password” label=“Password” /> The Checkbox Tag <s:checkbox name=“cricket” label=“Cricket” fieldValue=“C”/> <s:checkbox name=“hockey” label=“Hockey” fieldValue=“H”/> The Radio Tag <s:radio name=“m_status” label=“Marital Status” list=“{‘Single’,’Married’}” /> The Hidden Tag <s:hidden name=“empid” value=“Some Value” /> UI
  • 41. The Combo box <s:combobox label=“Country" headerKey="-1" headerValue="--- Select ---" list=“country" name=“country" /> class Action extends ActionSupport { private List<String> country; public void setCountry(List<String> country) { } public List<String> getCountryList() { } } The submit tag <s:submit/> The datetimepicker tag <s:datetimepicker name=“dob” label =“Date of Birth” displayFormat="dd MMMM, yyyy" /> UI
  • 42. Using Freemarker template for Creating Custom UI
  • 43. FreeMarker is a "template engine"; a generic tool to generate text output To Print the Values in FTL Welcome ${user} If condition in FTL <#if field.formatType??> </#if> Loops in FTL <#list tabList as page> </#list> Freemarker
  • 44. Creating Own Components Using FTL Eg. Creating Password Field Using FTL <input type="password" <#rt/> name="${parameters.name?default("")?html}"<#rt/> <#if parameters.get("size")??> size="${parameters.get("size")?html}"<#rt/> </#if> <#if parameters.maxlength??> maxlength="${parameters.maxlength?html}"<#rt/> </#if> <#if parameters.id??> id="${parameters.id?html}"<#rt/> </#if> <#if parameters.get("size")??> size="${parameters.get("size")?html}"<#rt/> </#if> <#if parameters.onblur??> onblur="${parameters.onblur?html}"<#rt/> </#if> /> NOTE: Store your FTL File in public-html template finnonepro Freemarker
  • 45. Calling FTL using <s:component tag> , place in JSP File <s:component template="password.ftl" theme="finnonepro" id="28000005" name="FW_SC_PW_OodPW"> <s:param name="maxlength" value="'20'"/> <s:param name="size" value="'12'"/> <s:param name="mandatory" value="'Y'"/> </s:component> Freemarker
  • 46. IOC (Inversion of Control) and DI (Dependency Injection) IOC and DI are programming design patterns, which are used to reduce coupling in programming. It follow the Following Principle: a) You do not need to create your objects. You need to only describe how they should be created. (This think is done by ObjectFactory) To enable the IOC in Struts a) Using an Enabler Interface Eg. SessionAware, ApplicationAware etc. IOC (Inversion of Control)
  • 47. IOC (Inversion of Control)
  • 48. Exercise: Create an Online Shopping Application, where user can login and register if the User is New. Once User login in the System , the Application display the items to the User , so User can choose it and buy the desire item. The Selected Item has the given features like Item Name , Size , Color , Quantity and Price. Once the User buy the selected item , the final bill is generated and display to the User
  • 49. Interceptor Interceptor is used for seperation of core functionality code in the form of Interceptors makes Action more lightweight. The purpose of Interceptors is to allow greater control over controller layer and separate some common logic that applies to multiple actions. All framework interceptors defined in struts-default.xml Interceptors
  • 50. Alias Interceptor Alias Interceptor This interceptor alias a named parameter to a different parameter name. Suppose your jsp having two textfield name t1 and t2 and in your action class you defined t3 and t4 variable , so alias interceptor can map t1 with t3 alias and t2 with t4 alias.
  • 53. Step-3 Entry in Struts.xml File
  • 56. ExecuteAndWait Interceptor While running a long action, the user may get impatient in case of a long delay in response. To avoid this, the execAndWait Interceptor is used, which runs a long running action in the background and display a page with a Loading to the user.
  • 58. Step -2 Create Action
  • 59. Step -3 Create Wait.jsp
  • 60. Step -4 Create struts.xml an initial delay in millis to wait before the wait page is shown Used for waking up at certain intervals to check if the background process is already done. Default is 100 millis
  • 61. Exception Interceptor The Struts 2 framework provides the functionality of exception handling through the Interceptor. Instead of displaying stack trace for the exception to the user, it is always good to show a nicely designed page describing the real problem to the user.
  • 63. Step -2 Create Action Class
  • 65. Step -4 exception jsp file
  • 66. Creating Own Interceptor This framework provides the flexibility to create own interceptor classes to enable additional logic which can be separated and refused in the Interceptor stack of different action classes. The Custom interceptor class need to be defined in the struts.xml file.
  • 67. Step -1 Create Interceptor Java File
  • 68. Step -2 Entry in struts.xml file
  • 69. Validation Framework Struts 2 based on a validation framework, which is provided by Xwork. The Validation framework uses external metadata in the form of XML files to describe what validation should be performed on your action. Struts2 Validation Framework allows us to separate the validation logic from actual Java/JSP code, where it can be reviewed and easily modified later. Validation can be perform a) Programmatic b) XML Meta Data Validation Framework
  • 70. Validation Using XML Meta-Data
  • 72. Step -2 Create Action Class
  • 73. Step -3 create validation.xml file
  • 74. Step -3 create validation.xml file
  • 75. Step -4 struts.xml Note: validation.xml file placed in the same location , where Action is placed and it is same name as action name and end with validation.xml file
  • 76. Programmatic Validation It is written in the Actionclass by overriding the validate method , this method calls automatically when user submit the page, it is call before the execute method , and if any error occurred , it return the “input” as a result , otherwise it execute the execute method of the action
  • 77. Step -1 Create an Action Override the validate method it comes from Validateable interface, which is implemented by ActionSupport class
  • 78. Internationalization Internationalization is a technique for application development that support multiple languages and data formats without having to rewrite programming logic. Create different languages application resource property file’s and these files name end with country language code Note: Also Specify the application resource name and path in struts.properties file, the path is required if you are not placed in application resoource file in the src folder