SlideShare une entreprise Scribd logo
1  sur  38
Continued….
 OGNL is an expression language that is used to
retrieve values from stack.
 Normally when actions are called, request
parameters, values passed to action, the action bean
instance, all are pushed into a stack called as “Value
Stack”.
 The value stack holds values for the action.
 OGNL is used in views to retrieve values from this
stack.
 The best thing about struts 2 is OGNL can also be used in the
struts.xml file.
 The following code specifies how OGNL can be used to specify
values in the value stack:
<action name=“ShowMail” class=“com.example.ShowMails”>
<result>/mails/showMails.jsp?username=${username}</result>
</action>
 This means when the result page would be rendered the url
would be appended with the value retrieved by the username
property of the present action class i.e. ShowMails.
 Apart from retrieving data from action class. OGNL helps retrieve data from the
following objects:
 #application
 #session
 #request
 #attr
 #parameters
 For example the following code would fetch the value username from the user
object in session.
<s:property value=“#session.user.username”/>
 This in essence is equivalent to:
<% User user=session.getAttribute(“user”);
Out.println(user.getUsername());
%>
 Functionality for creating views in JSP is provided by Struts
in the form of tag library.
 The struts tag library is included in the following way in
JSP pages that contain struts-tags:
<%@taglib uri=“/struts-tags” prefix=“s”%>
 The TLD file for the struts tags is present in the jar files of
the struts libraries.
 Struts tags fall into these two categories:
 Generic Tags: Generic tags control the execution flow when pages are
rendered. They are also used to extract data.
 UI Tags: UI Tags are used to create user interface elements like form
field etc.
 Apart from the tag library, Struts 2 also provides
OGNL(Object Graph Navigation Language), an intuitive way
to retrieve values and embed them in views from the
session, action beans etc.
 Generic Tags are of two types:
 Data Tags: They are used to retrieve data from objects
and display them in web pages.
 Control Tags: Control tags are used to emulate loops
and decision making constructs like while, for, for and
if…else.
 The action tag: This tag is used to invoke some other action
from the present page, where it is embedded. Its beneficial
when you want some functionality to be invoked in the JSP
page without using scriptlets.
 Syntax
<s:action name=“AuthenticateAction” executeResult=“true”/>
Attribute Meaning
Id For referencing the element
Name The name of the action that is being called
executeResult Whether the result of the action should be displayed
or not
Namespace Namespace of the action that has to be called
Flush Whether the writer should be flushed after execution
of this tag
var Reference name of the action bean so that it can be
used later in the page
ignoreContextParams Whether the request parameters are supposed to be
included while calling the action
 The property tag: The property tag is used to
inject values contained in objects into the JSP
page. These values are fetched from the value
stack (The value stack is a stack that contains
all the objects that the action is dealing with,
while the action‟s methods are called).
 Syntax:
<s:property value=“user.username”/>
 Output:
Hello Chandrakant
Attribute Meaning
id For referencing the element
value The value to be displayed
default If the attribute is not started then
the default value that would
appear in its place.
escape Whether HTML would be escaped.
 The bean tag: The bean tag is used to instantiate a class that
conforms to the java bean specification. It‟s similar to jsp‟s
useBean tag.
 Syntax
<s:bean name=“com.example.Employee” var=“emp”/>
Attribute Meaning
id For referencing the element
name Name of the class whose instance
is supposed to be created.
var Name of the reference for the bean
object that can be used later on.
 The set tag: This tag is used to set some data into a bean instance
or into one of the following:
 Session scope
 Application scope
 Request scope
 Page scope
 Action(by default)
 Syntax
<s:set name=“firstName” scope=“session” value=“user.firstName”/>
Attribute Meaning
Id For referencing the element
name Reference name of the variable
that is set in the specified scope.
value The value that is set
scope The scope in which the value
should be placed
 The include tag: This tag is used to include certain JSP page‟s
or Servlet‟s result into the present page. Its functionality
similar to the jsp include action.
 Syntax
 <s:include value=“listAllDepartments.jsp”/>
Attribute Meaning
value The name of the JSP page or the
servlet‟s alias that has to be
included in the present page.
 The url tag: The url tag is used to
 Render absolute or relative URLs
 Handle parameters
 Encodes URL‟s so that it can be used in browsers where cookies are
disabled.
 Syntax
<s:url action=“Login.action” var=“loginURL”>
<s:param name=“useType” value=“Admin”/>
</s:url>
Attribute Meaning
Id For referencing the element
value The base url
action Name of the target Action
namespace Namespace of the action that has to be called
encode Used to add session id to the url
var Reference name of the url so that it can be used
later in the page
includeParams/include To include the parameters or the context
method The method of the action that has to be called
Method The method of the action that has to be used
Scheme The protocol(http/https)
 The param tag: This tag is used for providing parameters to
other tags.
 Syntax:
<s:param name=“color”>#ff0000</s:param>
Attribute Meaning
id For referencing the element
name The name of the parameters to be
set
value Value that has to be set for the
parameter
 Control tags used for referencing emulating control
structures like loops and decision constructs.
 There are basically two control tags
 Iterator tag
 If, elseif and else tags
 The iterator tag is used for iterating through the collections of objects.
The collections can be one of the following types:
 Collections
 Maps
 Enumeration
 Iterators
 Arrays
 Syntax:
<s:iterator status=“num” value=“{1, 2, 3, 4, 5}”>
<s:property value=“top”/>
</s:iterator>
Attribute Meaning
Id For referencing the element
Value The object to be iterated over
Status It is used to mention whether an
instance of the IteratorStatus
should be pushed into the stack in
each iteration.
 The if, elseif and else tags: These tags are used to emulate an if…else
if…else construct.
 Syntax:
<s:if test=“%{#userRole==„Admin‟}”/>
<!–- Do something here.. -->
</s:if>
<s:elseif test=“%{#userRole==„HR‟}”/>
<!–- Something else--> -- >
<s:else>
<!– Do what should be done if all fails. -->
</s:else>
Attribute Meaning
Id For referencing the element
Test The expression of that needs to be
tested to determine if body of the
tag would be executed.
 UI Tags are used to generate form elements or display data in simple are
reusable format.
 Tags, themes and templates combine together to produce flexible,
feature-rich and extensible UI components.
 The struts UI tags are backed by templates that do the actual work.
 Templates group together to form themes. The various themes are:
 simple
 ajax
 Xhtml
 css_xhtml
 UI Tags are used to create form elements.
 The following are few Struts UI Tags:
◦ s:form, s:textfield, s:password, s:hidden, s:textarea, s:submit,
s:file, s:checkbox, s:select, s:radio, s:reset
 Views are usually specified in the struts.xml as results of actions. For
instance:
<action name=“LoginScreen”>
<result>login.jsp</result
</action>
 The result tag has a type attribute that can take the following values:
 Redirect – This is specified as the value of type if we want the controller to redirect
to a different page on the event of an action‟s result. This can redirect to another
JSP page or servlet.
 redirectAction – This is similar to redirect, however with redirectAction, the name
of some other action can be specified.
 The struts2 validation framework is one of the most comprehensive
ones that struts 2 core is composed of.
 Struts 2 provides support for both server-side and client-side
validation.
 A lot of predefined validators and ability to create and plug in
custom validators adds to the validation prowess of the framework.
 Struts provides both declarative and programmatic validation
techniques.
 Programmatic validation is achieved in Action classes by implementing the
Validateable interface in the action class.
 This interface has the void validate() method, which needs to be overridden.
 Validation code is put in this function.
 In case the Action class needs to report the validation errors, then it needs to
implement the ValidationAware interface that has methods for error logging.
These two interfaces are implemented in the ActionSupport class. So
extending ActionSupport automatically makes the action class possess validation
capabilities. All that needs to be done is overriding of the validate() method and
reporting of the validation errors.
 Usually programmatic validation is used in complex validation scenarios.
 In case things like pattern of input data, input data length, data
type(number or string or email address) have to be validated, declarative
validation is a better choice.
 Declarative validation is done in xml files that are present in the same
directory as the Action class.
 These files are named in this manner
 <Action class name>-validation.xml
 For instance if the name of the Action class is Employee the
validation.xml file would be:
 Employee-validation.xml
<validators>
<field name=“count”>
<field-validator type=“int” short-circuit=“true”>
<param name=“min”>1</param>
<param name=“max”>100</param>
<message key=“invalid.count”>
value must be between ${min} and ${max}
</message>
</field-validator>
</field>
<field name=“name”>
…
</field>
…
…
</validators>
 Inside the validation xml file there can be multiple <field></field>
entries, each corresponding to a property of the action class.
 The <field> element may be contain one or more <field-validator>
entries. Each of these field-validator represents a validation rule.
 The type attribute of the <field-validator< tag specifies what kind of
validation is required.
 The short-circuit attribute(if set to true) would prevent the rest of the
validators from validating.
 Param tags can be used to specify validation parameters.
 Validators can either act upon single fields or can
act upon the whole action context.
 In case a validator has to act upon the whole action
context then instead of <field-validator>, the
<validator> tag is used.
 <validator> has a higher precedence over <field-
validator>
Validator type Parameters
required fieldName
requiredString fieldName, trim
stringLength fieldName, maxLength, minLength, trim
Int fieldName, min, max
Double fieldName, maxInclusive, minExclusive, maxExclusive
Date fieldName, max, min
Expression Expression
fieldExpression Expression
Email fieldName
url fieldName
Conversion fieldName
Regex fieldName, expression, caseSensitive, trim
 In case errors are encountered during validation(programmatic or
declarative), the result of the action automatically becomes input.
 Therefore to handle result of type input, there should be an appropriate
element in struts.xml.
 For example:
<action name=“SaveEmployeeDetails” class=“com.example.Employee”>
<result name=“input”>employeeForm.jsp</result>
<result name=“success”>saveSuccess.jsp</result>
</action>

Contenu connexe

Tendances

JPA 2.1 performance tuning tips
JPA 2.1 performance tuning tipsJPA 2.1 performance tuning tips
JPA 2.1 performance tuning tipsosa_ora
 
Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPASubin Sugunan
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Trainingsourabh aggarwal
 
SAP Testing Training
SAP Testing TrainingSAP Testing Training
SAP Testing TrainingVGlobal Govi
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesecosio GmbH
 
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...Jorge Hidalgo
 
Introduction to JPA (JPA version 2.0)
Introduction to JPA (JPA version 2.0)Introduction to JPA (JPA version 2.0)
Introduction to JPA (JPA version 2.0)ejlp12
 
Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1PawanMM
 

Tendances (20)

Struts2 - 101
Struts2 - 101Struts2 - 101
Struts2 - 101
 
Struts2.x
Struts2.xStruts2.x
Struts2.x
 
Struts
StrutsStruts
Struts
 
Jpa 2.1 Application Development
Jpa 2.1 Application DevelopmentJpa 2.1 Application Development
Jpa 2.1 Application Development
 
JPA Best Practices
JPA Best PracticesJPA Best Practices
JPA Best Practices
 
JPA 2.1 performance tuning tips
JPA 2.1 performance tuning tipsJPA 2.1 performance tuning tips
JPA 2.1 performance tuning tips
 
Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPA
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 
Annotations
AnnotationsAnnotations
Annotations
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
 
Advance Java
Advance JavaAdvance Java
Advance Java
 
SAP Testing Training
SAP Testing TrainingSAP Testing Training
SAP Testing Training
 
Hibernate in Nutshell
Hibernate in NutshellHibernate in Nutshell
Hibernate in Nutshell
 
Java Annotations
Java AnnotationsJava Annotations
Java Annotations
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examples
 
Java Annotation
Java AnnotationJava Annotation
Java Annotation
 
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
 
Introduction to JPA (JPA version 2.0)
Introduction to JPA (JPA version 2.0)Introduction to JPA (JPA version 2.0)
Introduction to JPA (JPA version 2.0)
 
hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPA
 
Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1
 

En vedette

Introduction To FHA Origination
Introduction To FHA OriginationIntroduction To FHA Origination
Introduction To FHA OriginationDanMcElrath
 
Customer loan origination system
Customer loan origination systemCustomer loan origination system
Customer loan origination systemSandeep Verma
 
Core banking has changed the way you bank
Core banking has changed the way you bankCore banking has changed the way you bank
Core banking has changed the way you bankSushil Deshmukh
 
fraudGUARD Insurance Presentation 2010
fraudGUARD Insurance Presentation 2010fraudGUARD Insurance Presentation 2010
fraudGUARD Insurance Presentation 2010riskfinance
 
Mini project on core banking solutions
Mini project on core banking solutionsMini project on core banking solutions
Mini project on core banking solutionskeerthiredddy
 
Mortgage loan origination chap 6 by dr sam ruturi
Mortgage loan origination  chap 6 by dr sam ruturiMortgage loan origination  chap 6 by dr sam ruturi
Mortgage loan origination chap 6 by dr sam ruturisamruturi
 
Customer Loan Origination System - Part 2 (Web)
Customer Loan Origination System - Part 2 (Web)Customer Loan Origination System - Part 2 (Web)
Customer Loan Origination System - Part 2 (Web)Sandeep Verma
 
Misys acquires Custom Credit Systems, a leading provider of credit workflow ...
Misys acquires Custom Credit Systems, a leading provider  of credit workflow ...Misys acquires Custom Credit Systems, a leading provider  of credit workflow ...
Misys acquires Custom Credit Systems, a leading provider of credit workflow ...Misys
 
Loan origination platform
Loan origination platformLoan origination platform
Loan origination platformCapAnalec
 
Empowering dealers with new loan origination system
Empowering dealers with new loan origination systemEmpowering dealers with new loan origination system
Empowering dealers with new loan origination systemStrategybeach
 
Asset Based=Collateral Based Lending
Asset Based=Collateral Based LendingAsset Based=Collateral Based Lending
Asset Based=Collateral Based LendingSuzy Oubre
 
Eric Anklesaria. Secure SDLC - Core Banking
Eric Anklesaria. Secure SDLC - Core BankingEric Anklesaria. Secure SDLC - Core Banking
Eric Anklesaria. Secure SDLC - Core BankingPositive Hack Days
 
Core banking chapter 4
Core banking chapter 4Core banking chapter 4
Core banking chapter 4Nayan Vaghela
 
Online Loan Application & Its Verification System
Online Loan Application & Its Verification SystemOnline Loan Application & Its Verification System
Online Loan Application & Its Verification SystemSoban Ahmad
 
Don’t Fear Modernizing Your Core: Banking Innovation in the Digital Age
Don’t Fear Modernizing Your Core: Banking Innovation in the Digital AgeDon’t Fear Modernizing Your Core: Banking Innovation in the Digital Age
Don’t Fear Modernizing Your Core: Banking Innovation in the Digital AgeNTT DATA Consulting, Inc.
 
Chapterwise LOAN MANAGEMENT
Chapterwise LOAN MANAGEMENTChapterwise LOAN MANAGEMENT
Chapterwise LOAN MANAGEMENTsagartimilsina
 
Audit through core banking solution
Audit through core banking solutionAudit through core banking solution
Audit through core banking solutionCharudutt Marathe
 

En vedette (20)

Introduction To FHA Origination
Introduction To FHA OriginationIntroduction To FHA Origination
Introduction To FHA Origination
 
Customer loan origination system
Customer loan origination systemCustomer loan origination system
Customer loan origination system
 
Core banking has changed the way you bank
Core banking has changed the way you bankCore banking has changed the way you bank
Core banking has changed the way you bank
 
fraudGUARD Insurance Presentation 2010
fraudGUARD Insurance Presentation 2010fraudGUARD Insurance Presentation 2010
fraudGUARD Insurance Presentation 2010
 
Mini project on core banking solutions
Mini project on core banking solutionsMini project on core banking solutions
Mini project on core banking solutions
 
Mortgage loan origination chap 6 by dr sam ruturi
Mortgage loan origination  chap 6 by dr sam ruturiMortgage loan origination  chap 6 by dr sam ruturi
Mortgage loan origination chap 6 by dr sam ruturi
 
Customer Loan Origination System - Part 2 (Web)
Customer Loan Origination System - Part 2 (Web)Customer Loan Origination System - Part 2 (Web)
Customer Loan Origination System - Part 2 (Web)
 
Misys acquires Custom Credit Systems, a leading provider of credit workflow ...
Misys acquires Custom Credit Systems, a leading provider  of credit workflow ...Misys acquires Custom Credit Systems, a leading provider  of credit workflow ...
Misys acquires Custom Credit Systems, a leading provider of credit workflow ...
 
Loan origination platform
Loan origination platformLoan origination platform
Loan origination platform
 
Empowering dealers with new loan origination system
Empowering dealers with new loan origination systemEmpowering dealers with new loan origination system
Empowering dealers with new loan origination system
 
Asset Based=Collateral Based Lending
Asset Based=Collateral Based LendingAsset Based=Collateral Based Lending
Asset Based=Collateral Based Lending
 
Gold Loan Software | Gold Loan Management Software
Gold Loan Software | Gold Loan Management SoftwareGold Loan Software | Gold Loan Management Software
Gold Loan Software | Gold Loan Management Software
 
Eric Anklesaria. Secure SDLC - Core Banking
Eric Anklesaria. Secure SDLC - Core BankingEric Anklesaria. Secure SDLC - Core Banking
Eric Anklesaria. Secure SDLC - Core Banking
 
Core Banking Solution.
Core Banking Solution.Core Banking Solution.
Core Banking Solution.
 
Finacle - Menus and F Keys
Finacle - Menus and F KeysFinacle - Menus and F Keys
Finacle - Menus and F Keys
 
Core banking chapter 4
Core banking chapter 4Core banking chapter 4
Core banking chapter 4
 
Online Loan Application & Its Verification System
Online Loan Application & Its Verification SystemOnline Loan Application & Its Verification System
Online Loan Application & Its Verification System
 
Don’t Fear Modernizing Your Core: Banking Innovation in the Digital Age
Don’t Fear Modernizing Your Core: Banking Innovation in the Digital AgeDon’t Fear Modernizing Your Core: Banking Innovation in the Digital Age
Don’t Fear Modernizing Your Core: Banking Innovation in the Digital Age
 
Chapterwise LOAN MANAGEMENT
Chapterwise LOAN MANAGEMENTChapterwise LOAN MANAGEMENT
Chapterwise LOAN MANAGEMENT
 
Audit through core banking solution
Audit through core banking solutionAudit through core banking solution
Audit through core banking solution
 

Similaire à Struts 2

Struts Intro Course(1)
Struts Intro Course(1)Struts Intro Course(1)
Struts Intro Course(1)wangjiaz
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)Ajay Khatri
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep DiveGabriel Walt
 
Bt0083 server side programing 2
Bt0083 server side programing  2Bt0083 server side programing  2
Bt0083 server side programing 2Techglyphs
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullySpringPeople
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTAAFREEN SHAIKH
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point developmentPranav Sharma
 
Asp.net mvc training
Asp.net mvc trainingAsp.net mvc training
Asp.net mvc trainingicubesystem
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVCRichard Paul
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
Qtp Training
Qtp TrainingQtp Training
Qtp Trainingmehramit
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_HourDilip Patel
 

Similaire à Struts 2 (20)

Struts Intro Course(1)
Struts Intro Course(1)Struts Intro Course(1)
Struts Intro Course(1)
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
Struts N E W
Struts N E WStruts N E W
Struts N E W
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
Actionview
ActionviewActionview
Actionview
 
Bt0083 server side programing 2
Bt0083 server side programing  2Bt0083 server side programing  2
Bt0083 server side programing 2
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point development
 
Asp.net mvc training
Asp.net mvc trainingAsp.net mvc training
Asp.net mvc training
 
Struts 1
Struts 1Struts 1
Struts 1
 
Automation tips
Automation tipsAutomation tips
Automation tips
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
Struts Overview
Struts OverviewStruts Overview
Struts Overview
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Qtp Training
Qtp TrainingQtp Training
Qtp Training
 
Asp.NET MVC
Asp.NET MVCAsp.NET MVC
Asp.NET MVC
 
Android best practices
Android best practicesAndroid best practices
Android best practices
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
Struts Ppt 1
Struts Ppt 1Struts Ppt 1
Struts Ppt 1
 

Dernier

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
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
 

Dernier (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
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
 

Struts 2

  • 2.  OGNL is an expression language that is used to retrieve values from stack.  Normally when actions are called, request parameters, values passed to action, the action bean instance, all are pushed into a stack called as “Value Stack”.  The value stack holds values for the action.  OGNL is used in views to retrieve values from this stack.
  • 3.  The best thing about struts 2 is OGNL can also be used in the struts.xml file.  The following code specifies how OGNL can be used to specify values in the value stack: <action name=“ShowMail” class=“com.example.ShowMails”> <result>/mails/showMails.jsp?username=${username}</result> </action>  This means when the result page would be rendered the url would be appended with the value retrieved by the username property of the present action class i.e. ShowMails.
  • 4.  Apart from retrieving data from action class. OGNL helps retrieve data from the following objects:  #application  #session  #request  #attr  #parameters  For example the following code would fetch the value username from the user object in session. <s:property value=“#session.user.username”/>  This in essence is equivalent to: <% User user=session.getAttribute(“user”); Out.println(user.getUsername()); %>
  • 5.  Functionality for creating views in JSP is provided by Struts in the form of tag library.  The struts tag library is included in the following way in JSP pages that contain struts-tags: <%@taglib uri=“/struts-tags” prefix=“s”%>  The TLD file for the struts tags is present in the jar files of the struts libraries.
  • 6.  Struts tags fall into these two categories:  Generic Tags: Generic tags control the execution flow when pages are rendered. They are also used to extract data.  UI Tags: UI Tags are used to create user interface elements like form field etc.  Apart from the tag library, Struts 2 also provides OGNL(Object Graph Navigation Language), an intuitive way to retrieve values and embed them in views from the session, action beans etc.
  • 7.  Generic Tags are of two types:  Data Tags: They are used to retrieve data from objects and display them in web pages.  Control Tags: Control tags are used to emulate loops and decision making constructs like while, for, for and if…else.
  • 8.  The action tag: This tag is used to invoke some other action from the present page, where it is embedded. Its beneficial when you want some functionality to be invoked in the JSP page without using scriptlets.  Syntax <s:action name=“AuthenticateAction” executeResult=“true”/>
  • 9. Attribute Meaning Id For referencing the element Name The name of the action that is being called executeResult Whether the result of the action should be displayed or not Namespace Namespace of the action that has to be called Flush Whether the writer should be flushed after execution of this tag var Reference name of the action bean so that it can be used later in the page ignoreContextParams Whether the request parameters are supposed to be included while calling the action
  • 10.  The property tag: The property tag is used to inject values contained in objects into the JSP page. These values are fetched from the value stack (The value stack is a stack that contains all the objects that the action is dealing with, while the action‟s methods are called).  Syntax: <s:property value=“user.username”/>  Output: Hello Chandrakant
  • 11. Attribute Meaning id For referencing the element value The value to be displayed default If the attribute is not started then the default value that would appear in its place. escape Whether HTML would be escaped.
  • 12.  The bean tag: The bean tag is used to instantiate a class that conforms to the java bean specification. It‟s similar to jsp‟s useBean tag.  Syntax <s:bean name=“com.example.Employee” var=“emp”/>
  • 13. Attribute Meaning id For referencing the element name Name of the class whose instance is supposed to be created. var Name of the reference for the bean object that can be used later on.
  • 14.  The set tag: This tag is used to set some data into a bean instance or into one of the following:  Session scope  Application scope  Request scope  Page scope  Action(by default)  Syntax <s:set name=“firstName” scope=“session” value=“user.firstName”/>
  • 15. Attribute Meaning Id For referencing the element name Reference name of the variable that is set in the specified scope. value The value that is set scope The scope in which the value should be placed
  • 16.  The include tag: This tag is used to include certain JSP page‟s or Servlet‟s result into the present page. Its functionality similar to the jsp include action.  Syntax  <s:include value=“listAllDepartments.jsp”/>
  • 17. Attribute Meaning value The name of the JSP page or the servlet‟s alias that has to be included in the present page.
  • 18.  The url tag: The url tag is used to  Render absolute or relative URLs  Handle parameters  Encodes URL‟s so that it can be used in browsers where cookies are disabled.  Syntax <s:url action=“Login.action” var=“loginURL”> <s:param name=“useType” value=“Admin”/> </s:url>
  • 19. Attribute Meaning Id For referencing the element value The base url action Name of the target Action namespace Namespace of the action that has to be called encode Used to add session id to the url var Reference name of the url so that it can be used later in the page includeParams/include To include the parameters or the context method The method of the action that has to be called Method The method of the action that has to be used Scheme The protocol(http/https)
  • 20.  The param tag: This tag is used for providing parameters to other tags.  Syntax: <s:param name=“color”>#ff0000</s:param>
  • 21. Attribute Meaning id For referencing the element name The name of the parameters to be set value Value that has to be set for the parameter
  • 22.  Control tags used for referencing emulating control structures like loops and decision constructs.  There are basically two control tags  Iterator tag  If, elseif and else tags
  • 23.  The iterator tag is used for iterating through the collections of objects. The collections can be one of the following types:  Collections  Maps  Enumeration  Iterators  Arrays  Syntax: <s:iterator status=“num” value=“{1, 2, 3, 4, 5}”> <s:property value=“top”/> </s:iterator>
  • 24. Attribute Meaning Id For referencing the element Value The object to be iterated over Status It is used to mention whether an instance of the IteratorStatus should be pushed into the stack in each iteration.
  • 25.  The if, elseif and else tags: These tags are used to emulate an if…else if…else construct.  Syntax: <s:if test=“%{#userRole==„Admin‟}”/> <!–- Do something here.. --> </s:if> <s:elseif test=“%{#userRole==„HR‟}”/> <!–- Something else--> -- > <s:else> <!– Do what should be done if all fails. --> </s:else>
  • 26. Attribute Meaning Id For referencing the element Test The expression of that needs to be tested to determine if body of the tag would be executed.
  • 27.  UI Tags are used to generate form elements or display data in simple are reusable format.  Tags, themes and templates combine together to produce flexible, feature-rich and extensible UI components.  The struts UI tags are backed by templates that do the actual work.  Templates group together to form themes. The various themes are:  simple  ajax  Xhtml  css_xhtml
  • 28.  UI Tags are used to create form elements.  The following are few Struts UI Tags: ◦ s:form, s:textfield, s:password, s:hidden, s:textarea, s:submit, s:file, s:checkbox, s:select, s:radio, s:reset
  • 29.  Views are usually specified in the struts.xml as results of actions. For instance: <action name=“LoginScreen”> <result>login.jsp</result </action>  The result tag has a type attribute that can take the following values:  Redirect – This is specified as the value of type if we want the controller to redirect to a different page on the event of an action‟s result. This can redirect to another JSP page or servlet.  redirectAction – This is similar to redirect, however with redirectAction, the name of some other action can be specified.
  • 30.
  • 31.  The struts2 validation framework is one of the most comprehensive ones that struts 2 core is composed of.  Struts 2 provides support for both server-side and client-side validation.  A lot of predefined validators and ability to create and plug in custom validators adds to the validation prowess of the framework.  Struts provides both declarative and programmatic validation techniques.
  • 32.  Programmatic validation is achieved in Action classes by implementing the Validateable interface in the action class.  This interface has the void validate() method, which needs to be overridden.  Validation code is put in this function.  In case the Action class needs to report the validation errors, then it needs to implement the ValidationAware interface that has methods for error logging. These two interfaces are implemented in the ActionSupport class. So extending ActionSupport automatically makes the action class possess validation capabilities. All that needs to be done is overriding of the validate() method and reporting of the validation errors.
  • 33.  Usually programmatic validation is used in complex validation scenarios.  In case things like pattern of input data, input data length, data type(number or string or email address) have to be validated, declarative validation is a better choice.  Declarative validation is done in xml files that are present in the same directory as the Action class.  These files are named in this manner  <Action class name>-validation.xml  For instance if the name of the Action class is Employee the validation.xml file would be:  Employee-validation.xml
  • 34. <validators> <field name=“count”> <field-validator type=“int” short-circuit=“true”> <param name=“min”>1</param> <param name=“max”>100</param> <message key=“invalid.count”> value must be between ${min} and ${max} </message> </field-validator> </field> <field name=“name”> … </field> … … </validators>
  • 35.  Inside the validation xml file there can be multiple <field></field> entries, each corresponding to a property of the action class.  The <field> element may be contain one or more <field-validator> entries. Each of these field-validator represents a validation rule.  The type attribute of the <field-validator< tag specifies what kind of validation is required.  The short-circuit attribute(if set to true) would prevent the rest of the validators from validating.  Param tags can be used to specify validation parameters.
  • 36.  Validators can either act upon single fields or can act upon the whole action context.  In case a validator has to act upon the whole action context then instead of <field-validator>, the <validator> tag is used.  <validator> has a higher precedence over <field- validator>
  • 37. Validator type Parameters required fieldName requiredString fieldName, trim stringLength fieldName, maxLength, minLength, trim Int fieldName, min, max Double fieldName, maxInclusive, minExclusive, maxExclusive Date fieldName, max, min Expression Expression fieldExpression Expression Email fieldName url fieldName Conversion fieldName Regex fieldName, expression, caseSensitive, trim
  • 38.  In case errors are encountered during validation(programmatic or declarative), the result of the action automatically becomes input.  Therefore to handle result of type input, there should be an appropriate element in struts.xml.  For example: <action name=“SaveEmployeeDetails” class=“com.example.Employee”> <result name=“input”>employeeForm.jsp</result> <result name=“success”>saveSuccess.jsp</result> </action>