WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
Struts2
1. Struts is based on the MVC design pattern
Struts controller uses the Command design pattern
Action classes use the Adapter design pattern.
The process () method of the Request Processor uses the Template method design pattern.
Struts also implement the following J2EE design patterns.
Struts components
• Struts Apps
• Struts EL
• Struts Extras
• Struts Faces
• Struts Scripting
• Struts Taglib
• Struts Tiles
Front End Controllers
Struts1.x --- Action Servlet class is the front end controller
Struts2.x---Filter Dispatcher class is the front end controller
Exceptional Handling Struts
Exceptions are defined in Configuration file and if the exception occurs the control is automatically passed to the
appropriate error page
Struts1.x - Exceptions are defined in the struts-config.xml file. The <exception> tag is used to define the
exception in the struts-config.xml file.
For Example : (( If RuntimeException in SaveEmpAaction class , control goes to exception.jsp)
<action path="/saveEmp" type="com.techfaq.SaveEmpAaction" input="/empform.jsp" >
<exception key="error.system" type="java.lang.RuntimeException" path="/exception.jsp" />
</action>
<global-exceptions>
<exception key="some.key" type="java.lang.NullPointerException"
path="/WEB-INF/errors/null.jsp"/>
</global-exceptions>
2. Struts2.x -
Exceptions are defined in the struts.Xml file. The <exception-mapping> tag is used to define the exception in the
struts.xml file.
For Example: (( If Runtime Exception in SaveEmpAaction class , control goes to exception.jsp)
<action name=”” class=”” method=””>
<exception-mapping result="" exception=""></exception-mapping>
</action>
<global-exception-mappings><exception-mapping result="" exception=""></exception-mapping></global-
exception-mappings>
Struts Tag Libraries
Struts Taglib is composed of four distinct tag libraries: Bean, HTML, Logic, and Nested.
Tag library reference for the following tag libraries:
• bean (struts-bean.tld) - uri: http://struts.apache.org/tags-bean
• html (struts-html.tld) - uri: http://struts.apache.org/tags-html
• logic (struts-logic.tld) - uri: http://struts.apache.org/tags-logic
• nested (struts-nested.tld) - uri: http://struts.apache.org/tags-nested
tiles (struts-tiles.tld) - uri: http://struts.apache.org/tags-tiles
Bean
• cookie Define a scripting variable based on the value(s) of the specified request
cookie
• define Define a scripting variable based on the value(s) of the specified bean
property
• header Define a scripting variable based on the value(s) of the specified request
header
• include Load the response from a dynamic application request and make it available
as a bean
• message Render an internationalized message string to the response
• page Expose a specified item from the page context as a bean
3. • parameter Define a scripting variable based on the value(s) of the specified request
parameter
• resource Load a web application resource and make it available as a bean
• size Define a bean containing the number of elements in a Collection or Map
• struts Expose a named Struts internal configuration object as a bean
• write Render the value of the specified bean property to the current JspWriter
HTML
• base Render an HTML <base> Element Renders an HTML <base> element
with an href attribute pointing to the absolute location of the enclosing JSP page
• button Render A Button Input Field Renders an HTML <input> element of type
button, populated from the specified value or the content of this tag body
• cancel Render a Cancel Button Renders an HTML <input> element of type
submit
• checkbox Render A Checkbox Input Field Renders an HTML <input> element of
type checkbox, populated from the specified value or the specified property of the
bean associated with our current form
• errors Conditionally display a set of accumulated error messages
• file Render A File Select Input Field Renders an HTML <input> element of type
file, defaulting to the specified value or the specified property of the bean associated
with our current form
• form Define An Input Form Renders an HTML <form> element whose contents
are described by the body content of this tag
• frame Render an HTML frame element Renders an HTML <frame> element with
processing for the src attribute that is identical to that performed by the
<html:link> tag for the href attribute
• hidden Render A Hidden Field Renders an HTML <input> element of type
hidden, populated from the specified value or the specified property of the bean
associated with our current form
• html Render an HTML <html> Element Renders an HTML <html> element
with language attributes extracted from the user's current Locale object, if there is
one
• image Render an input tag of type "image" Renders an HTML <input> tag of
type "image"
• img Render an HTML img tag Renders an HTML <img> element with the image
at the specified URL
• javascript Render JavaScript validation based on the validation rules loaded by the
ValidatorPlugIn
• link Render an HTML anchor or hyperlink Renders an HTML <a> element as an
anchor definition (if "linkName" is specified) or as a hyperlink to the specified URL
• messages Conditionally display a set of accumulated messages
• multibox Render A Checkbox Input Field Renders an HTML <input> element of
type checkbox, whose "checked" status is initialized based on whether the specified
value matches one of the elements of the underlying property's array of current
values
• option Render A Select Option Render an HTML <option> element, representing
one of the choices for an enclosing <select> element
• options Render a Collection of Select Options Renders a set of HTML <option>
elements, representing possible choices for a <select> element
4. • optionsCollection Render a Collection of Select Options Renders a set of HTML
<option> elements, representing possible choices for a <select> element
• param Adds a parameter to the following tags: <html:frame> <html:link>
<html:rewrite> Since: Struts 1
• password Render A Password Input Field Renders an HTML <input> element of
type password, populated from the specified value or the specified property of the
bean associated with our current form
• radio Render A Radio Button Input Field Renders an HTML <input> element of
type radio, populated from the specified property of the bean associated with our
current form
• reset Render A Reset Button Input Field Renders an HTML <input> element of
type reset
• rewrite Render an URI Renders a request URI based on exactly the same rules as the
<html:link> tag does, but without creating the <a> hyperlink
• select Render A Select Element Renders an HTML <select> element, associated
with a bean property specified by our attributes
• submit Render A Submit Button Renders an HTML <input> element of type
submit
• text Render An Input Field of Type text Render an input field of type text
• textarea Render A Textarea Render a textarea element
• xhtml Render HTML tags as XHTML Using this tag in a page tells all other html taglib
tags to render themselves as XHTML 1
Logic
• empty Evaluate the nested body content of this tag if the requested variable is either
null or an empty string
• equal Evaluate the nested body content of this tag if the requested variable is equal
to the specified value
• forward Forward control to the page specified by the specified ActionForward entry
• greaterEqual Evaluate the nested body content of this tag if the requested variable is
greater than or equal to the specified value
• greaterThan Evaluate the nested body content of this tag if the requested variable is
greater than the specified value
• iterate Repeat the nested body content of this tag over a specified collection
• lessEqual Evaluate the nested body content of this tag if the requested variable is
less than or equal to the specified value
• lessThan Evaluate the nested body content of this tag if the requested variable is less
than the specified value
• match Evaluate the nested body content of this tag if the specified value is an
appropriate substring of the requested variable
• messagesNotPresent Generate the nested body content of this tag if the specified
message is not present in any scope
• messagesPresent Generate the nested body content of this tag if the specified
message is present in any scope
• notEmpty Evaluate the nested body content of this tag if the requested variable is
neither null, nor an empty string, nor an empty java
• notEqual Evaluate the nested body content of this tag if the requested variable is not
equal to the specified value
5. • notMatch Evaluate the nested body content of this tag if the specified value is not an
appropriate substring of the requested variable
• notPresent Generate the nested body content of this tag if the specified value is not
present in this request
• present Generate the nested body content of this tag if the specified value is present
in this request
• redirect Render an HTTP Redirect Performs an HttpServletResponse
Nested.
• checkbox Nested Extension - Render A Checkbox Input Field This tag is an extension
of the <html:checkbox> tag
• define Nested Extension - Define a scripting variable based on the value(s) of the
specified bean property
• empty Nested Extension - Evaluate the nested body content of this tag if the
requested variable is either null or an empty string
• equal Nested Extension - Evaluate the nested body content of this tag if the
requested variable is equal to the specified value
• errors Nested Extension - Conditionally display a set of accumulated error messages
• file Nested Extension - Render A File Select Input Field This tag is an extension of the
<html:file> tag
• form Nested Extension - Define An Input Form This tag is an extension of the
<html:form> tag
• greaterEqual Nested Extension - Evaluate the nested body content of this tag if the
requested variable is greater than or equal to the specified value
• greaterThan Nested Extension - Evaluate the nested body content of this tag if the
requested variable is greater than the specified value
• hidden Nested Extension - Render A Hidden Field This tag is an extension of the
<html:hidden> tag
• image Nested Extension - Render an input tag of type "image" This tag is an
extension of the <html:image> tag
• img Nested Extension - Render an HTML "img" tag This tag is an extension of the
<html:img> tag
• iterate Nested Extension - Repeat the nested body content of this tag over a
specified collection
• lessEqual Nested Extension - Evaluate the nested body content of this tag if the
requested variable is greater than or equal to the specified value
• lessThan Nested Extension - Evaluate the nested body content of this tag if the
requested variable is less than the specified value
• link Nested Extension - Render an HTML anchor or hyperlink This tag is an extension
of the <html:link> tag
• match Nested Extension - Evaluate the nested body content of this tag if the
specified value is an appropriate substring of the requested variable
• message Nested Extension - Render an internationalized message string to the
response
• messages Nested Extension - Conditionally display a set of accumulated messages
• messagesNotPresent Nested Extension - Generate the nested body content of this
tag if the specified message is not present in this request
• messagesPresent Nested Extension - Generate the nested body content of this tag if
the specified message is present in this request
6. • multibox Nested Extension - Render A Checkbox Input Field This tag is an extension
of the <html:multibox> tag
• nest Defines a new level of nesting for child tags to reference to This tag provides a
simple method of defining a logical nesting level in the nested hierarchy
• notEmpty Nested Extension - Evaluate the nested body content of this tag if the
requested variable is neither null nor an empty string
• notEqual Nested Extension - Evaluate the nested body content of this tag if the
requested variable is not equal to the specified value
• notMatch Nested Extension - Evaluate the nested body content of this tag if the
specified value is not an appropriate substring of the requested variable
• notPresent Nested Extension - Generate the nested body content of this tag if the
specified value is not present in this request
• options Nested Extension - Render a Collection of Select Options This tag is an
extension of the <html:options> tag
• optionsCollection Nested Extension - Render a Collection of Select Options This tag is
an extension of the <html:optionsCollection> tag
• password Nested Extension - Render A Password Input Field This tag is an extension
of the <html:password> tag
• present Nested Extension - Generate the nested body content of this tag if the
specified value is present in this request
• radio Nested Extension - Render A Radio Button Input Field This tag is an extension
of the <html:radio> tag
• root To start off a nested hierarchy without the need for a form This tag is provided
to allow the nested tags to find a common bean reference without the need for a
form and its relative overhead
• select Nested Extension - Render A Select Element This tag is an extension of the
<html:select> tag
• size Nested Extension - Define a bean containing the number of elements in a
Collection or Map
• submit Nested Extension - Render A Submit Button This tag is an extension of the
<html:submit> tag
• text Nested Extension - Render An Input Field of Type text This tag is an extension of
the <html:text> tag
• textarea Nested Extension - Render A Textarea This tag is an extension of the
<html:textarea> tag
• write Nested Extension - Render the value of the specified bean property to the
current JspWriter
• writeNesting Writes or makes a scripting variable of the current nesting level
Required attributes are marked with a *
http://www.bullraider.com/java/struts2/interview-questions
http://struts.apache.org/1.x/struts-taglib/index.html