• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Struts2
 

Struts2

on

  • 645 views

 

Statistics

Views

Total Views
645
Views on SlideShare
645
Embed Views
0

Actions

Likes
0
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Struts2 Struts2 Document Transcript

    • 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>
    • Struts2.x -Exceptions are defined in the struts.Xml file. The <exception-mapping> tag is used to define the exception in thestruts.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 LibrariesStruts 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-tilesBean • 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
    • • 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 JspWriterHTML • base Render an HTML &lt;base&gt; Element Renders an HTML &lt;base&gt; element with an href attribute pointing to the absolute location of the enclosing JSP page • button Render A Button Input Field Renders an HTML &lt;input&gt; element of type button, populated from the specified value or the content of this tag body • cancel Render a Cancel Button Renders an HTML &lt;input&gt; element of type submit • checkbox Render A Checkbox Input Field Renders an HTML &lt;input&gt; 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 &lt;input&gt; 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 &lt;form&gt; element whose contents are described by the body content of this tag • frame Render an HTML frame element Renders an HTML &lt;frame&gt; element with processing for the src attribute that is identical to that performed by the &lt;html:link&gt; tag for the href attribute • hidden Render A Hidden Field Renders an HTML &lt;input&gt; 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 &lt;html&gt; Element Renders an HTML &lt;html&gt; element with language attributes extracted from the users current Locale object, if there is one • image Render an input tag of type "image" Renders an HTML &lt;input&gt; tag of type "image" • img Render an HTML img tag Renders an HTML &lt;img&gt; 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 &lt;a&gt; 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 &lt;input&gt; element of type checkbox, whose "checked" status is initialized based on whether the specified value matches one of the elements of the underlying propertys array of current values • option Render A Select Option Render an HTML &lt;option&gt; element, representing one of the choices for an enclosing &lt;select&gt; element • options Render a Collection of Select Options Renders a set of HTML &lt;option&gt; elements, representing possible choices for a &lt;select&gt; element
    • • optionsCollection Render a Collection of Select Options Renders a set of HTML &lt;option&gt; elements, representing possible choices for a &lt;select&gt; element • param Adds a parameter to the following tags: &lt;html:frame&gt; &lt;html:link&gt; &lt;html:rewrite&gt; Since: Struts 1 • password Render A Password Input Field Renders an HTML &lt;input&gt; 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 &lt;input&gt; 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 &lt;input&gt; element of type reset • rewrite Render an URI Renders a request URI based on exactly the same rules as the &lt;html:link&gt; tag does, but without creating the &lt;a&gt; hyperlink • select Render A Select Element Renders an HTML &lt;select&gt; element, associated with a bean property specified by our attributes • submit Render A Submit Button Renders an HTML &lt;input&gt; 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 1Logic • 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
    • • 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 HttpServletResponseNested. • checkbox Nested Extension - Render A Checkbox Input Field This tag is an extension of the &lt;html:checkbox&gt; 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 &lt;html:file&gt; tag • form Nested Extension - Define An Input Form This tag is an extension of the &lt;html:form&gt; 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 &lt;html:hidden&gt; tag • image Nested Extension - Render an input tag of type "image" This tag is an extension of the &lt;html:image&gt; tag • img Nested Extension - Render an HTML "img" tag This tag is an extension of the &lt;html:img&gt; 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 &lt;html:link&gt; 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
    • • multibox Nested Extension - Render A Checkbox Input Field This tag is an extension of the &lt;html:multibox&gt; 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 &lt;html:options&gt; tag • optionsCollection Nested Extension - Render a Collection of Select Options This tag is an extension of the &lt;html:optionsCollection&gt; tag • password Nested Extension - Render A Password Input Field This tag is an extension of the &lt;html:password&gt; 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 &lt;html:radio&gt; 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 &lt;html:select&gt; 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 &lt;html:submit&gt; tag • text Nested Extension - Render An Input Field of Type text This tag is an extension of the &lt;html:text&gt; tag • textarea Nested Extension - Render A Textarea This tag is an extension of the &lt;html:textarea&gt; 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 levelRequired attributes are marked with a *http://www.bullraider.com/java/struts2/interview-questionshttp://struts.apache.org/1.x/struts-taglib/index.html