SlideShare a Scribd company logo
1 of 90
SKILLWISE-STRUTS.X
2
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)
1. Get Request parameters
Business Service
(Model)
2. Call Business Service
DB
Business Service talk to DB
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.
MVC1 vs MVC 2
Struts1 vs Struts2 Flow
Struts 2 Web Flow
Struts 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.
ActionProxy reads the configuration
file such as struts.xml.
ActionProxy creates an instance
of ActionInvocation class and
delegates 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.
ActionInvocation is responsible
to invokes the Interceptors one by
one (if required) and then invoke
the 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
responsible 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.
The Interceptors are executed
again in reverse order and the
response is returned to the Filter
(In most cases to FilterDispatcher).
And the result is then sent to the
servlet container which in turns
send 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 https://struts.apache.org/download.cgi
Step -1 Struts Filter Entry in web.xml
Web.xml
<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>
Step -2 Create an Action Class
Creating Action
Step -3 Create a View
<%@ taglib prefix="s" uri="/struts-tags" %>
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.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="welcome" class="com.srivastava.basics.HelloAction">
<result name="success">/index.jsp</result>
</action>
<action name="loginCheck" class="com.srivastava.basics.HelloAction"
method="checkLogin" >
<result name="login">/welcome.jsp</result>
<result name="error"></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
Dependency
In action execute method , it has
HttpServletRequest and
HttpServletResponse Object, both
comes from servlet API
Not needed in struts 2 execute method
Testablity A major hurdle to testing Struts 1
Actions is that the execute method
exposes the Servlet API. A third-
party extension, Struts TestCase,
offers a set of mock object for Struts
1.
Struts 2 Actions can be tested by instantiating the
Action, setting properties, and invoking methods.
Dependency Injection support also makes testing
simpler.
No Action
Form
Struts 1 uses an ActionForm object
to capture input. Like Actions, all
ActionForms must extend a base
class. Since other JavaBeans cannot
be used as ActionForms, developers
often create redundant classes to
capture input.
Struts 2 uses Action properties as input properties,
eliminating the need for a second input objec
Control Of
Action
Execution
Struts 1 supports separate Request
Processors (lifecycles) for each
module, but all the Actions in the
module must share the same
lifecycle.
Struts 2 supports creating different lifecycles on a per
Action basis via Interceptor Stacks.
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 TagsControl Tags
Skillwise Struts.x

More Related Content

What's hot

Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Matt Raible
 
important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questionssurendray
 
JPA lifecycle events practice
JPA lifecycle events practiceJPA lifecycle events practice
JPA lifecycle events practiceGuo Albert
 
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 desaijinaldesailive
 
Developing Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring toolsDeveloping Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring toolsSathish Chittibabu
 
Identifing Listeners and Filters
Identifing Listeners and FiltersIdentifing Listeners and Filters
Identifing Listeners and FiltersPeople Strategists
 
Android application model
Android application modelAndroid application model
Android application modelmagicshui
 
Stellar Sakai Integration
Stellar Sakai IntegrationStellar Sakai Integration
Stellar Sakai Integrationjiali zhang
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureAlexey Buzdin
 
Advance java session 11
Advance java session 11Advance java session 11
Advance java session 11Smita B Kumar
 
java code and document security
java code and document securityjava code and document security
java code and document securityAnkit Desai
 

What's hot (18)

Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2
 
Struts notes
Struts notesStruts notes
Struts notes
 
important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questions
 
Spring survey
Spring surveySpring survey
Spring survey
 
JPA lifecycle events practice
JPA lifecycle events practiceJPA lifecycle events practice
JPA lifecycle events practice
 
04 Data Access
04 Data Access04 Data Access
04 Data Access
 
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
 
Introduction to Struts 2
Introduction to Struts 2Introduction to Struts 2
Introduction to Struts 2
 
Developing Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring toolsDeveloping Agile Java Applications using Spring tools
Developing Agile Java Applications using Spring tools
 
Identifing Listeners and Filters
Identifing Listeners and FiltersIdentifing Listeners and Filters
Identifing Listeners and Filters
 
Android application model
Android application modelAndroid application model
Android application model
 
Stellar Sakai Integration
Stellar Sakai IntegrationStellar Sakai Integration
Stellar Sakai Integration
 
Ecom lec4 fall16_jpa
Ecom lec4 fall16_jpaEcom lec4 fall16_jpa
Ecom lec4 fall16_jpa
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Grails with swagger
Grails with swaggerGrails with swagger
Grails with swagger
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Advance java session 11
Advance java session 11Advance java session 11
Advance java session 11
 
java code and document security
java code and document securityjava code and document security
java code and document security
 

Similar to Skillwise Struts.x

Struts2 course chapter 1: Evolution of Web Applications
Struts2 course chapter 1: Evolution of Web ApplicationsStruts2 course chapter 1: Evolution of Web Applications
Struts2 course chapter 1: Evolution of Web ApplicationsJavaEE Trainers
 
Krazykoder struts2 intro
Krazykoder struts2 introKrazykoder struts2 intro
Krazykoder struts2 introKrazy Koder
 
Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questionsjbashask
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Strutsyesprakash
 
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
 
Struts 2 – Architecture
Struts 2 – ArchitectureStruts 2 – Architecture
Struts 2 – ArchitectureDucat India
 

Similar to Skillwise Struts.x (20)

Struts
StrutsStruts
Struts
 
Struts
StrutsStruts
Struts
 
Struts2
Struts2Struts2
Struts2
 
Struts2 course chapter 1: Evolution of Web Applications
Struts2 course chapter 1: Evolution of Web ApplicationsStruts2 course chapter 1: Evolution of Web Applications
Struts2 course chapter 1: Evolution of Web Applications
 
Krazykoder struts2 intro
Krazykoder struts2 introKrazykoder struts2 intro
Krazykoder struts2 intro
 
Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questions
 
Struts ppt 1
Struts ppt 1Struts ppt 1
Struts ppt 1
 
Struts Basics
Struts BasicsStruts Basics
Struts Basics
 
Struts Interceptors
Struts InterceptorsStruts Interceptors
Struts Interceptors
 
Struts Ppt 1
Struts Ppt 1Struts Ppt 1
Struts Ppt 1
 
Struts 1
Struts 1Struts 1
Struts 1
 
Struts
StrutsStruts
Struts
 
Struts2
Struts2Struts2
Struts2
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Struts
 
Struts2 notes
Struts2 notesStruts2 notes
Struts2 notes
 
141060753008 3715301
141060753008 3715301141060753008 3715301
141060753008 3715301
 
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
 
Struts 2 – Architecture
Struts 2 – ArchitectureStruts 2 – Architecture
Struts 2 – Architecture
 
Lecture 05 web_applicationframeworks
Lecture 05 web_applicationframeworksLecture 05 web_applicationframeworks
Lecture 05 web_applicationframeworks
 

More from Skillwise Group

Skillwise Consulting New updated
Skillwise Consulting New updatedSkillwise Consulting New updated
Skillwise Consulting New updatedSkillwise Group
 
Retailing & logistics profile
Retailing & logistics profileRetailing & logistics profile
Retailing & logistics profileSkillwise Group
 
Overview- Skillwise Consulting
Overview- Skillwise Consulting Overview- Skillwise Consulting
Overview- Skillwise Consulting Skillwise Group
 
Skillwise corporate presentation
Skillwise corporate presentationSkillwise corporate presentation
Skillwise corporate presentationSkillwise Group
 
Skillwise Softskill Training Workshop
Skillwise Softskill Training WorkshopSkillwise Softskill Training Workshop
Skillwise Softskill Training WorkshopSkillwise Group
 
Skillwise Insurance profile
Skillwise Insurance profileSkillwise Insurance profile
Skillwise Insurance profileSkillwise Group
 
Skillwise Train and Hire Services
Skillwise Train and Hire ServicesSkillwise Train and Hire Services
Skillwise Train and Hire ServicesSkillwise Group
 
Skillwise Digital Technology
Skillwise Digital Technology Skillwise Digital Technology
Skillwise Digital Technology Skillwise Group
 
Skillwise Boot Camp Training
Skillwise Boot Camp TrainingSkillwise Boot Camp Training
Skillwise Boot Camp TrainingSkillwise Group
 
Skillwise Academy Profile
Skillwise Academy ProfileSkillwise Academy Profile
Skillwise Academy ProfileSkillwise Group
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSkillwise Group
 
Skillwise - Business writing
Skillwise - Business writing Skillwise - Business writing
Skillwise - Business writing Skillwise Group
 

More from Skillwise Group (20)

Skillwise Consulting New updated
Skillwise Consulting New updatedSkillwise Consulting New updated
Skillwise Consulting New updated
 
Email Etiquette
Email Etiquette Email Etiquette
Email Etiquette
 
Healthcare profile
Healthcare profileHealthcare profile
Healthcare profile
 
Manufacturing courses
Manufacturing coursesManufacturing courses
Manufacturing courses
 
Retailing & logistics profile
Retailing & logistics profileRetailing & logistics profile
Retailing & logistics profile
 
Skillwise orientation
Skillwise orientationSkillwise orientation
Skillwise orientation
 
Overview- Skillwise Consulting
Overview- Skillwise Consulting Overview- Skillwise Consulting
Overview- Skillwise Consulting
 
Skillwise corporate presentation
Skillwise corporate presentationSkillwise corporate presentation
Skillwise corporate presentation
 
Skillwise Profile
Skillwise ProfileSkillwise Profile
Skillwise Profile
 
Skillwise Softskill Training Workshop
Skillwise Softskill Training WorkshopSkillwise Softskill Training Workshop
Skillwise Softskill Training Workshop
 
Skillwise Insurance profile
Skillwise Insurance profileSkillwise Insurance profile
Skillwise Insurance profile
 
Skillwise Train and Hire Services
Skillwise Train and Hire ServicesSkillwise Train and Hire Services
Skillwise Train and Hire Services
 
Skillwise Digital Technology
Skillwise Digital Technology Skillwise Digital Technology
Skillwise Digital Technology
 
Skillwise Boot Camp Training
Skillwise Boot Camp TrainingSkillwise Boot Camp Training
Skillwise Boot Camp Training
 
Skillwise Academy Profile
Skillwise Academy ProfileSkillwise Academy Profile
Skillwise Academy Profile
 
Skillwise Overview
Skillwise OverviewSkillwise Overview
Skillwise Overview
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
 
Skillwise - Business writing
Skillwise - Business writing Skillwise - Business writing
Skillwise - Business writing
 
Imc.ppt
Imc.pptImc.ppt
Imc.ppt
 
Skillwise cics part 1
Skillwise cics part 1Skillwise cics part 1
Skillwise cics part 1
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 

Skillwise Struts.x

  • 3. 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
  • 4. 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
  • 6. Servlet (Controller) 1. Get Request parameters Business Service (Model) 2. Call Business Service DB Business Service talk to DB JSP (View) 3. Pass the result to the JSP 4. Return Formatted HTML MVC
  • 7. 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.
  • 8. 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
  • 9. 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.
  • 12.
  • 13.
  • 14. Struts 2 Web Flow Struts MVC Flow
  • 15. 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
  • 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. It is optional Filter , and it is used to integrate the Struts with SiteMesh Plugin 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. 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
  • 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. The FilterDispatcher filter is called which consults the ActionMapper to determine whether an Action should be invoked Struts Architecture
  • 19. 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
  • 20. 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. ActionProxy reads the configuration file such as struts.xml. ActionProxy creates an instance of ActionInvocation class and delegates the control. Struts Architecture
  • 21. 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. ActionInvocation is responsible to invokes the Interceptors one by one (if required) and then invoke the Action. Struts Architecture
  • 22. 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 responsible for looking up the proper result associated with the Action result code mapped in struts.xml. Struts Architecture
  • 23. 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 Interceptors are executed again in reverse order and the response is returned to the Filter (In most cases to FilterDispatcher). And the result is then sent to the servlet container which in turns send it back to client Struts Architecture
  • 24. Develop Struts First Application
  • 25. 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 https://struts.apache.org/download.cgi
  • 26. Step -1 Struts Filter Entry in web.xml Web.xml <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>
  • 27. Step -2 Create an Action Class Creating Action
  • 28. Step -3 Create a View <%@ taglib prefix="s" uri="/struts-tags" %>
  • 29. 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.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="default" namespace="/" extends="struts-default"> <action name="welcome" class="com.srivastava.basics.HelloAction"> <result name="success">/index.jsp</result> </action> <action name="loginCheck" class="com.srivastava.basics.HelloAction" method="checkLogin" > <result name="login">/welcome.jsp</result> <result name="error"></result> </action> </package> </struts>
  • 37. 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 Dependency In action execute method , it has HttpServletRequest and HttpServletResponse Object, both comes from servlet API Not needed in struts 2 execute method Testablity A major hurdle to testing Struts 1 Actions is that the execute method exposes the Servlet API. A third- party extension, Struts TestCase, offers a set of mock object for Struts 1. Struts 2 Actions can be tested by instantiating the Action, setting properties, and invoking methods. Dependency Injection support also makes testing simpler. No Action Form Struts 1 uses an ActionForm object to capture input. Like Actions, all ActionForms must extend a base class. Since other JavaBeans cannot be used as ActionForms, developers often create redundant classes to capture input. Struts 2 uses Action properties as input properties, eliminating the need for a second input objec Control Of Action Execution Struts 1 supports separate Request Processors (lifecycles) for each module, but all the Actions in the module must share the same lifecycle. Struts 2 supports creating different lifecycles on a per Action basis via Interceptor Stacks.
  • 38. 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>
  • 43. 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
  • 44. 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
  • 45. 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
  • 46. Using Freemarker template for Creating Custom UI
  • 47. 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
  • 48. 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
  • 49. 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
  • 50. 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)
  • 51. IOC (Inversion of Control)
  • 52. 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
  • 53. 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
  • 54. 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.
  • 57. Step-3 Entry in Struts.xml File
  • 60. 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.
  • 62. Step -2 Create Action
  • 63. Step -3 Create Wait.jsp
  • 64. 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
  • 65. 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.
  • 67. Step -2 Create Action Class
  • 69. Step -4 exception jsp file
  • 70. 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.
  • 71. Step -1 Create Interceptor Java File
  • 72. Step -2 Entry in struts.xml file
  • 73. 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
  • 74. Validation Using XML Meta-Data
  • 76. Step -2 Create Action Class
  • 77. Step -3 create validation.xml file
  • 78. Step -3 create validation.xml file
  • 79. 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
  • 80. 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
  • 81. Step -1 Create an Action Override the validate method it comes from Validateable interface, which is implemented by ActionSupport class
  • 82. 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