SlideShare uma empresa Scribd logo
1 de 76
INTRODUCTION TO  STRUTS Part of the Jakarta Project Sponsored by the Apache Software Foundation Developed by: Roger W Barnes of Project Refinery, Inc.
[object Object],[object Object],[object Object],[object Object]
Model-View-Controller Design Pattern ,[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object]
STRUTS  MVC Design Pattern
STRUTS  MVC Design Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object]
STRUTS  MVC Design Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object]
Model Components Unit 2
STRUTS  Model Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
STRUTS  Model Components ,[object Object],[object Object],[object Object],[object Object],[object Object]
STRUTS  Model Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
STRUTS  Model Components ,[object Object],[object Object],[object Object]
STRUTS  Model Components ,[object Object],[object Object],[object Object]
STRUTS  Model Components ,[object Object],[object Object],[object Object]
STRUTS  Model Components ,[object Object],[object Object],[object Object],[object Object]
STRUTS  Model Components ,[object Object],[object Object]
STRUTS  Model Components ,[object Object],[object Object],[object Object]
View Components Unit 3
STRUTS  View Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
STRUTS  View Components ,[object Object],[object Object],[object Object],[object Object]
STRUTS  View Components ,[object Object],[object Object],[object Object]
STRUTS  View Components ,[object Object],[object Object],[object Object],[object Object]
STRUTS  View Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
STRUTS  View Components ,[object Object],[object Object],[object Object],[object Object]
Controller Components Unit 4
STRUTS  Controller Components ,[object Object]
STRUTS  Controller Components ,[object Object],[object Object],[object Object],[object Object],[object Object]
STRUTS  Controller Components ,[object Object],[object Object],[object Object]
STRUTS  Controller Components ,[object Object]
STRUTS  Controller Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
STRUTS  Controller Components ,[object Object],[object Object],[object Object]
STRUTS  Controller Components ,[object Object],[object Object],[object Object]
STRUTS  Controller Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
STRUTS  Controller Components ,[object Object],[object Object],[object Object],[object Object]
STRUTS  Controller Components ,[object Object],[object Object],[object Object]
STRUTS  Controller Components ,[object Object],[object Object],[object Object],[object Object]
STRUTS  Controller Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
STRUTS  Controller Components ,[object Object],[object Object]
Tag Libraries Unit 5
Tag Libraries   A bean holds a reference to another bean internally, and all access to that bean is handled through the current bean. This act of having one bean's access go through another bean is known as "nesting beans". The first bean is known as the parent bean. The bean which it references , is known as a child bean. The terms "parent" and "child" are commonly used to describe the model's hierarchy.  nested   This tag library contains tags that are useful in managing conditional generation of output text, looping over object collections for repetitive generation of output text, and application flow management. Tags that do value comparisons (equal, greaterThan, lessThan, notEqual) and substring matching (match, notMatch)   logic   This taglib contains tags used to create struts input forms, as well as other tags generally useful in the creation of HTML-based user interfaces html   This tag library contains tags useful in accessing beans and their properties, as well as defining new beans (based on these accesses) that are accessible to the remainder of the page via scripting variables and page scope attributes . bean
HTML Tag Summary   Generates  client-side JavaScript Validation code for validations defined in the Validator framework’s validation.xml file. javascript   Generates an HTML<img> tag. img   Generates an HTML<input type=“image”> tag. image   Generates an HTML<html> tag. html   Generates an HTML<input type=“hidden”> tag. hidden   Generates an HTML<frame> tag. frame   Generates an HTML<form> tag. form   Generates an HTML<input type=“file”> tag. file   Displays a set of error messages prepared by a business logic component and stored as an  org.apache.struts.action.ActionErrors  object.   errors   Generates an HTML<input type=“checkbox”> tag. checkbox   Generates an HTML<input type=“submit”> tag, when excuted causes Struts Cancel feature to be triggered. cancel   Generates an HTML<input type=“button”> tag. button   Generates an HTML <base> tag with its  href  attribute set to absolute URL of the enclosing JSP.   base
Generates an HTML  <option>  tags for each element in a collection. optionscollection Generates an HTML  <input type=“submit”>  tag. submit Generates an HTML  <input type=“text”>  tag. text Generates an HTML  <textarea>  tag. textarea Instructs the rest of the tag in HTML Tag Library to generate their output as XHTML instead of HTML. xhtml Generates an HTML  <select>  tag select Generates a URL by specifying a base URL and optionally specifying an and query string parameters to add to the URL.  rewrite Generates an HTML  <input type=“reset”>  tag reset Generates an HTML  <input type=“radio”>  tag radio Generates an HTML  <input type=“password”>  tag password Generates an HTML  <option>  tag option Generates an HTML  <input type=“checkbox”>  tag . multibox Displays a set of messages stored as an  org.apache.struts.action.ActionErrors  object messages Generates an HTML hyperlink  <a>  tag. link
HTML Tags  – Typical HTML Form < HTML> <BODY> <FORM> <TABLE WIDTH=&quot;100%&quot;> <TR><TD>First Name</TD> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Name&quot; SIZE=&quot;40&quot; MAXLENGTH=&quot;40&quot;></TD></TR> <TR><TD>Street Address</TD> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Address&quot; SIZE=&quot;40&quot; MAXLENGTH=&quot;40&quot;></TD></TR> <TR><TD>City</TD> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;City&quot; SIZE=&quot;20&quot; MAXLENGTH=&quot;20&quot;></TD></TR> <TR><TD>State</TD> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;State&quot; SIZE=&quot;2&quot; MAXLENGTH=&quot;2&quot;></TD></TR> <TR><TD>Postal Code</TD> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;ZipCode&quot; SIZE=&quot;9&quot; MAXLENGTH=&quot;9&quot;></TD></TR> <TR><TD ALIGN=CENTER><INPUT TYPE=&quot;SUBMIT&quot; NAME=&quot;Submit&quot; VALUE=&quot;Save&quot;></TD> <TD><INPUT TYPE=&quot;RESET&quot; NAME=&quot;Reset&quot; VALUE=&quot;Cancel&quot;></TD></TR> </TABLE> </FORM> </BODY> </HTML>
HTML Tags  – Typical Struts Form < HTML:HTML> <BODY> <HTML:FORM Action=&quot;/CustomerForm&quot; focus=“name” > <TABLE WIDTH=&quot;100%&quot;> <TR><TD><bean:message key=&quot;customer.name&quot;/></TD> <TD><HTML:TEXT property=&quot;name&quot; size=&quot;40&quot; maxlength=&quot;40&quot; /></TD></TR> <TR><TD><bean:message key=&quot;customer.address&quot;/></TD> <TD><HTML:TEXT property=&quot;address&quot; size =&quot;40&quot; maxlength =&quot;40&quot; /></TD></TR> <TR><TD><bean:message key=&quot;customer.city&quot;/></TD> <TD><HTML:TEXT property=&quot;city&quot; size =&quot;20&quot; maxlength =&quot;20&quot; /></TD></TR> <TR><TD><bean:message key=&quot;customer.state&quot;/></TD> <TD><HTML:TEXT property=&quot;state&quot; size =&quot;2&quot; maxlength =&quot;2&quot; /></TD></TR> <TR><TD><bean:message key=&quot;customer.zip&quot;/></TD> <TD><HTML:TEXT property=&quot;zip&quot; size =&quot;9&quot; maxlength =&quot;9&quot; /></TD></TR> <TR><TD ALIGN=CENTER><html:submit property=&quot;action&quot; value =&quot;Save&quot;/></TD> <TD><html:reset property=&quot;action&quot; value =&quot;Reset&quot;/></TD></TR> </TABLE> </HTML:FORM> </BODY> </HTML:HTML>
Logic Tag Library Tags Wraps content that is conditionally processes based on whether a specified object’s value contains, starts with, or ends with a specified constant value. match Wraps content that is conditionally processes based on whether a specified object’s value is less than specified constant value lessThan Wraps content that is conditionally processes based on whether a specified object’s value is less than or equal to specified constant value. lessEqual Wraps content that is repeated for each element of a specified collection. iterate Wraps content that is conditionally processes based on whether a specified object’s value is greater than specified constant value. greaterThan Wraps content that is conditionally processes based on whether a specified object’s value is greater than or equal to specified constant value. greaterEqual Looks up a forward from the struts configuration file and processes it. forward Wraps content that is conditionally processes based on whether a specified object’s value equals a specified constant value. equal Wraps content that is conditionally processes based on whether the specified object is  null  or contains an empty (zero-length)  String . empty
Composes a URL to another page and then redirects to it. redirect Wraps content that is conditionally processes based on whether a specified object exists. present Wraps content that is conditionally processes based on whether a specified object does not exist. notPresent Wraps content that is conditionally processes based on whether a specified object’s   value does not   contain, start with, or end with a specified constant value. notMatch Wraps content that is conditionally processes based on whether the specified object is  not equal  to a specified constant value . notEqual Wraps content that is conditionally processes based on whether the specified object is   non -null  and does not contain an empty  String . notEmpty Wraps content that is conditionally processes based on whether Struts’  org.apache.struts.Action.ActionErrors   or  org.apache.struts.action. .ActionMessages  object has any errors or messages in it, respectively messagesPresent Wraps content that is conditionally processes based on whether Struts’  org.apache.struts.Action.ActionErrors   or  org.apache.struts.action. .ActionMessages  object does not have any  errors or messages in it. messagesNotPresent
Nested Tag Library Tags Nesting-enabled version of the Logic Tag Library’s  iterate  tag. iterate Nesting-enabled version of the HTML Tag Library’s  img  tag. img Nesting-enabled version of the HTML Tag Library’s  image  tag. image Nesting-enabled version of the HTML Tag Library’s  hidden  tag. hidden Nesting-enabled version of the Logic Tag Library’s  lessEqual  tag. lessEqual Nesting-enabled version of the Logic Tag Library’s  greaterThan  tag. greaterThan Nesting-enabled version of the Logic Tag Library’s  greaterEqual  tag. greaterEqual Nesting-enabled version of the HTML Tag Library’s  form  tag. form Nesting-enabled version of the HTML Tag Library’s  file  tag. file Nesting-enabled version of the HTML Tag Library’s  errors  tag. errors Nesting-enabled version of the Logic Tag Library’s  equal  tag. equal Nesting-enabled version of the Logic Tag Library’s  empty  tag. empty Nesting-enabled version of the Bean Tag Library’s  define  tag. define Nesting-enabled version of the HTML Tag Library’s  checkbox  tag. checkbox
Nesting-enabled version of the HTML Tag Library’s  options  tag. options Nesting-enabled version of the Logic Tag Library’s  notPresent  tag. notPresent Nesting-enabled version of the Logic Tag Library’s  notMatch  tag. notMatch Nesting-enabled version of the Logic Tag Library’s  notEqual  tag. notEqual Nesting-enabled version of the Logic Tag Library’s  notEmpty  tag. notEmpty Defines a logical level in a nesting hierarchy and associates an object with it that all of its nested tags will be relative to. nest Nesting-enabled version of the HTML Tag Library’s  multibox  tag. multibox  Nesting-enabled version of the Logic Tag Library’s  messagesPresent  tag. messagesPresent Nesting-enabled version of the Logic Tag Library’s  messagesNotPresent  tag. messagesNotPresent Nesting-enabled version of the HTML Tag Library’s  messages  tag. messages Nesting-enabled version of the Bean Tag Library’s  message  tag. message Nesting-enabled version of the Logic Tag Library’s  match  tag. match Nesting-enabled version of the HTML Tag Library’s  link  tag. link Nesting-enabled version of the Logic Tag Library’s  lessThan  tag. lessThan
Renders or creates a JSP scripting variable for a string representation of the object related to the current nesting level. writeNesting Nesting-enabled version of the Bean Tag Library’s  write  tag. write Nesting-enabled version of the HTML Tag Library’s  textarea  tag. textarea Nesting-enabled version of the HTML Tag Library’s  text  tag. text Nesting-enabled version of the HTML Tag Library’s  submit  tag. submit Nesting-enabled version of the Bean Tag Library’s  size  tag. size Nesting-enabled version of the HTML Tag Library’s  select  tag. select Defines the root object of a nested hierarchy of objects. root Nesting-enabled version of the HTML Tag Library’s  radio  tag. radio Nesting-enabled version of the Logic Tag Library’s  present  tag. present Nesting-enabled version of the HTML Tag Library’s  password  tag. password Nesting-enabled version of the HTML Tag Library’s  optionsCollection  tag. optionsCollection
Bean Tags ,[object Object],[object Object],[object Object],[object Object]
Bean Tags   Tag Name Description 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 JspWriter.
Bean Tag Example <table border=&quot;2&quot;> <tr> <th align=&quot;left&quot;><bean:message key=“imagebroker.lob”/></th> <th align=&quot;left&quot;><bean:message key=“imagebroker.unitnbr”/></th> <th align=&quot;left&quot;><bean:message key=“imagebroker.onbase_dns”/></th> </tr> <logic:iterate id=&quot;image&quot; property=&quot;collection&quot;  name=&quot;ImageLocationListForm&quot;> <tr> <td><a href=&quot;ImageLocationListForm.do?lob=<bean:write name='image'  property='lob'/> &unitnbr=<bean:write name='image' property='unitnbr'/> &onbase_dns=<bean:write name='image' property='onbase_dns'/>&quot; > <bean:write name=&quot;image&quot; property=&quot;lob&quot;/></a></td> <td><bean:write name=&quot;image&quot; property=&quot;unitnbr&quot;/></td>  <td><bean:write name=&quot;image&quot; property=&quot;onbase_dns&quot;/></td>  </tr> </logic:iterate> </table>
Logic Tags ,[object Object]
Logic Tags ,[object Object],[object Object],[object Object],[object Object],[object Object]
Logic Tags ,[object Object],[object Object],[object Object],[object Object]
Logic Tags   Tag Name Description 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 requested variable is greater than or equal to 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 requested variable is greater than or equal to 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 specified value is an appropriate substring of requested variable.  messagesNotPresent Generate the nested body content of this tag if the specified message is not present in this request.  messagesPresent Generate the nested body content of this tag if the specified message is present in this request.  notEmpty Evaluate the nested body content of this tag if the requested variable is neither null nor an empty string.  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 tag if specified value not an appropriate substring of 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
Logic Tags - Example <html:html> <head> <title><bean:message key=&quot;imagebrokerlink.title&quot;/></title> <META name=&quot;GENERATOR&quot; content=&quot;IBM WebSphere Studio&quot;> </head> <body> <html:form action=&quot;/ImageLocationForm&quot; > <center> <font size=3> <br> <b> <logic:notEqual property=&quot;action&quot; name=&quot;ImageLocationForm&quot; value=&quot;Insert&quot;> <bean:message key=&quot;imagelocationdetail.title&quot;/> </logic:notEqual> <logic:equal property=&quot;action&quot; name=&quot;ImageLocationForm&quot; value=&quot;Insert&quot;> <bean:message key=&quot;imagelocationinsert.title&quot;/> </logic:equal> … …
Template Tags ,[object Object]
Template Tags ,[object Object],[object Object],[object Object]
Custom Tags  <%@ taglib uri=&quot;WEB-INF/imagebroker.tld&quot; prefix=&quot;broker&quot; %> <table width=750 cellspacing=0 cellpadding=2 border=2 > <tr> <td><broker:form  lob='<%=test.getLob()%>'  unitnbr='<%=test.getUnitnbr()%>'  userid='<%=test.getUserid()%>' > <broker:doctype value=&quot;Invoice&quot;/> <broker:keyword name=&quot;CompanyNbr&quot; value=&quot;55555&quot;/> <broker:keyword name=&quot;PONbr&quot; value=&quot;M12345&quot;/> <broker:constraint name=&quot;FromDate&quot; value=&quot;02/02/2002&quot;/> <broker:constraint name=&quot;ToDate&quot; value=&quot;02/28/2002&quot;/> Image Broker Link Test </broker:form> </td> </tr> </table>
Custom Tags – tld File <tag> <name>doctype</name> <tagclass>com.pri.brokertag.ImageBrokerDoctype</tagclass> <attribute> <name>value</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag>
Custom Tags – Tag Class public class ImageBrokerDoctype extends TagSupport { private String value = null; public int doStartTag() throws JspException { Hashtable ht = null; String keyword_count = null; int iCnt = 0; HttpServletRequest request = (HttpServletRequest)    pageContext.getRequest(); ht = (Hashtable) request.getAttribute(&quot;keyword_parms&quot;); keyword_count = (String)        request.getAttribute(&quot;queryobject_count&quot;); iCnt ++; ht.put(&quot;QueryObject&quot; + iCnt, value); request.setAttribute(&quot;keyword_parms&quot;, ht); request.setAttribute(&quot;queryobject_count&quot;, new String(new    Integer(iCnt).toString())); return EVAL_PAGE;  } }
STRUTS Configuration File Unit 6
STRUTS Configuration File ,[object Object]
STRUTS Configuration File ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Struts-config.xml <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; ?> <!DOCTYPE struts-config PUBLIC &quot;-//Apache Software Foundation//DTD Struts Configuration 1.0//EN&quot; &quot;http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd&quot;> <struts-config> <!-- ========== Form Bean Definitions =================================== --> <form-beans> <form-bean  name=&quot;CryptForm&quot; type=&quot;com.pri.imagebrokerWeb.CryptForm&quot; /> </form-beans> <!-- ========== Global Forward Definitions ============================== --> <global-forwards> <forward name=&quot;start&quot; path=&quot;/index.html&quot;/> </global-forwards> <!-- ========== Action Mapping Definitions ============================== --> <action-mappings> <action  path=&quot;/CryptForm&quot; type=&quot;com.pri.imagebrokerWeb.CryptAction&quot;  name=&quot;CryptForm&quot;  scope=&quot;request&quot;  input=&quot;/pgCrypt.jsp&quot;> <forward name=&quot;encrypt&quot;  path=&quot;/pgCryptDisplay.jsp&quot;/> </action> </action-mappings> </struts-config>
Web Application Descriptor File Unit 7
Web.xml File ,[object Object]
Web.xml File <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN&quot; &quot;http://java.sun.com/j2ee/dtds/web-app_2_2.dtd&quot;> <web-app id=&quot;WebApp&quot;> <display-name>imagebrokerWeb</display-name> <!-- Action Servlet Configuration --> <servlet id=&quot;Servlet_1&quot;> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>application</param-name><param-value>imagebrokerWeb</param-value> </init-param> <init-param> <param-name>config</param-name><param-value>WEB-INF/struts-config.xml</param-value> </init-param> </servlet>
Web.xml File - continued <!-- Action Servlet Mapping --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- The Welcome File List --> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list>
Web.xml File - continued <!-- Struts Tag Library Descriptors --> <taglib> <taglib-uri>WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> <taglib> <taglib-uri>WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> <taglib> <taglib-uri>WEB-INF/struts-logic.tld</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib> </web-app>
Application Resources File Unit 8
Application.properties File error.cryptvalue.required=<li>You must enter some text.</li> error.lob.required=<li>You must enter the Line of Business.</li> error.unitnbr.required=<li>You must enter the Unit Number.</li> error.onbase_dns.required=<li>You must enter the OnBase DNS.</li> imagebroker.linkname=Project Refinery, Inc. imagebroker.title=pri Image Broker imagebrokerlink.title=pri Image Broker Link Test imagelocationlist.title=Image Location List imagelocationdetail.title=Image Location Detail imagelocationinsert.title=Image Location Insert errors.header= errors.footer=
Resources Unit 9
Resources ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados

Spring MVC
Spring MVCSpring MVC
Spring MVCyuvalb
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVCJohn Lewis
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsGuy Nir
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsKaml Sah
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and DeploymentBG Java EE Course
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Tuna Tore
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server PageVipin Yadav
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC frameworkMohit Gupta
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Courseguest764934
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892Tuna Tore
 

Mais procurados (20)

Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Rest web service
Rest web serviceRest web service
Rest web service
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topics
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Spring jdbc
Spring jdbcSpring jdbc
Spring jdbc
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Spring core
Spring coreSpring core
Spring core
 
Struts notes
Struts notesStruts notes
Struts notes
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
Spring MVC Basics
Spring MVC BasicsSpring MVC Basics
Spring MVC Basics
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
 
Jsp
JspJsp
Jsp
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Course
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 

Semelhante a Struts N E W

Struts Intro Course(1)
Struts Intro Course(1)Struts Intro Course(1)
Struts Intro Course(1)wangjiaz
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Strutsyesprakash
 
Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questionsjbashask
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts frameworks4al_com
 
Struts interview-questions-ppt
Struts interview-questions-pptStruts interview-questions-ppt
Struts interview-questions-pptMayank Kumar
 
What is struts_en
What is struts_enWhat is struts_en
What is struts_entechbed
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overviewskill-guru
 
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
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questionsAkhil Mittal
 

Semelhante a Struts N E W (20)

Struts Intro Course(1)
Struts Intro Course(1)Struts Intro Course(1)
Struts Intro Course(1)
 
Struts Ppt 1
Struts Ppt 1Struts Ppt 1
Struts Ppt 1
 
MVC
MVCMVC
MVC
 
Struts ppt 1
Struts ppt 1Struts ppt 1
Struts ppt 1
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Struts
 
Struts
StrutsStruts
Struts
 
Session 1
Session 1Session 1
Session 1
 
Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questions
 
Struts
StrutsStruts
Struts
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
 
Struts interview-questions-ppt
Struts interview-questions-pptStruts interview-questions-ppt
Struts interview-questions-ppt
 
Struts 1
Struts 1Struts 1
Struts 1
 
What is struts_en
What is struts_enWhat is struts_en
What is struts_en
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
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
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
 
Struts course material
Struts course materialStruts course material
Struts course material
 
Ibm
IbmIbm
Ibm
 

Mais de patinijava

Mais de patinijava (18)

Web Services Part 2
Web Services Part 2Web Services Part 2
Web Services Part 2
 
Web Services Part 1
Web Services Part 1Web Services Part 1
Web Services Part 1
 
Session Management
Session  ManagementSession  Management
Session Management
 
S E R V L E T S
S E R V L E T SS E R V L E T S
S E R V L E T S
 
Struts Java I I Lecture 8
Struts  Java  I I  Lecture 8Struts  Java  I I  Lecture 8
Struts Java I I Lecture 8
 
Servlet Api
Servlet ApiServlet Api
Servlet Api
 
Servlet11
Servlet11Servlet11
Servlet11
 
Sping Slide 6
Sping Slide 6Sping Slide 6
Sping Slide 6
 
Entity Manager
Entity ManagerEntity Manager
Entity Manager
 
Ejb6
Ejb6Ejb6
Ejb6
 
Ejb5
Ejb5Ejb5
Ejb5
 
Ejb4
Ejb4Ejb4
Ejb4
 
Patni Hibernate
Patni   HibernatePatni   Hibernate
Patni Hibernate
 
Spring Transaction
Spring TransactionSpring Transaction
Spring Transaction
 
Webbasics
WebbasicsWebbasics
Webbasics
 
Internetbasics
InternetbasicsInternetbasics
Internetbasics
 
Jsp
JspJsp
Jsp
 
Portlet
PortletPortlet
Portlet
 

Último

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
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
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
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
 
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
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
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
 
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
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 

Último (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
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
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
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
 
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
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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?
 

Struts N E W

  • 1. INTRODUCTION TO STRUTS Part of the Jakarta Project Sponsored by the Apache Software Foundation Developed by: Roger W Barnes of Project Refinery, Inc.
  • 2.
  • 3.
  • 4.
  • 5. STRUTS MVC Design Pattern
  • 6.
  • 7.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 40. Tag Libraries A bean holds a reference to another bean internally, and all access to that bean is handled through the current bean. This act of having one bean's access go through another bean is known as &quot;nesting beans&quot;. The first bean is known as the parent bean. The bean which it references , is known as a child bean. The terms &quot;parent&quot; and &quot;child&quot; are commonly used to describe the model's hierarchy. nested This tag library contains tags that are useful in managing conditional generation of output text, looping over object collections for repetitive generation of output text, and application flow management. Tags that do value comparisons (equal, greaterThan, lessThan, notEqual) and substring matching (match, notMatch) logic This taglib contains tags used to create struts input forms, as well as other tags generally useful in the creation of HTML-based user interfaces html This tag library contains tags useful in accessing beans and their properties, as well as defining new beans (based on these accesses) that are accessible to the remainder of the page via scripting variables and page scope attributes . bean
  • 41. HTML Tag Summary Generates client-side JavaScript Validation code for validations defined in the Validator framework’s validation.xml file. javascript Generates an HTML<img> tag. img Generates an HTML<input type=“image”> tag. image Generates an HTML<html> tag. html Generates an HTML<input type=“hidden”> tag. hidden Generates an HTML<frame> tag. frame Generates an HTML<form> tag. form Generates an HTML<input type=“file”> tag. file Displays a set of error messages prepared by a business logic component and stored as an org.apache.struts.action.ActionErrors object. errors Generates an HTML<input type=“checkbox”> tag. checkbox Generates an HTML<input type=“submit”> tag, when excuted causes Struts Cancel feature to be triggered. cancel Generates an HTML<input type=“button”> tag. button Generates an HTML <base> tag with its href attribute set to absolute URL of the enclosing JSP. base
  • 42. Generates an HTML <option> tags for each element in a collection. optionscollection Generates an HTML <input type=“submit”> tag. submit Generates an HTML <input type=“text”> tag. text Generates an HTML <textarea> tag. textarea Instructs the rest of the tag in HTML Tag Library to generate their output as XHTML instead of HTML. xhtml Generates an HTML <select> tag select Generates a URL by specifying a base URL and optionally specifying an and query string parameters to add to the URL. rewrite Generates an HTML <input type=“reset”> tag reset Generates an HTML <input type=“radio”> tag radio Generates an HTML <input type=“password”> tag password Generates an HTML <option> tag option Generates an HTML <input type=“checkbox”> tag . multibox Displays a set of messages stored as an org.apache.struts.action.ActionErrors object messages Generates an HTML hyperlink <a> tag. link
  • 43. HTML Tags – Typical HTML Form < HTML> <BODY> <FORM> <TABLE WIDTH=&quot;100%&quot;> <TR><TD>First Name</TD> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Name&quot; SIZE=&quot;40&quot; MAXLENGTH=&quot;40&quot;></TD></TR> <TR><TD>Street Address</TD> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Address&quot; SIZE=&quot;40&quot; MAXLENGTH=&quot;40&quot;></TD></TR> <TR><TD>City</TD> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;City&quot; SIZE=&quot;20&quot; MAXLENGTH=&quot;20&quot;></TD></TR> <TR><TD>State</TD> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;State&quot; SIZE=&quot;2&quot; MAXLENGTH=&quot;2&quot;></TD></TR> <TR><TD>Postal Code</TD> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;ZipCode&quot; SIZE=&quot;9&quot; MAXLENGTH=&quot;9&quot;></TD></TR> <TR><TD ALIGN=CENTER><INPUT TYPE=&quot;SUBMIT&quot; NAME=&quot;Submit&quot; VALUE=&quot;Save&quot;></TD> <TD><INPUT TYPE=&quot;RESET&quot; NAME=&quot;Reset&quot; VALUE=&quot;Cancel&quot;></TD></TR> </TABLE> </FORM> </BODY> </HTML>
  • 44. HTML Tags – Typical Struts Form < HTML:HTML> <BODY> <HTML:FORM Action=&quot;/CustomerForm&quot; focus=“name” > <TABLE WIDTH=&quot;100%&quot;> <TR><TD><bean:message key=&quot;customer.name&quot;/></TD> <TD><HTML:TEXT property=&quot;name&quot; size=&quot;40&quot; maxlength=&quot;40&quot; /></TD></TR> <TR><TD><bean:message key=&quot;customer.address&quot;/></TD> <TD><HTML:TEXT property=&quot;address&quot; size =&quot;40&quot; maxlength =&quot;40&quot; /></TD></TR> <TR><TD><bean:message key=&quot;customer.city&quot;/></TD> <TD><HTML:TEXT property=&quot;city&quot; size =&quot;20&quot; maxlength =&quot;20&quot; /></TD></TR> <TR><TD><bean:message key=&quot;customer.state&quot;/></TD> <TD><HTML:TEXT property=&quot;state&quot; size =&quot;2&quot; maxlength =&quot;2&quot; /></TD></TR> <TR><TD><bean:message key=&quot;customer.zip&quot;/></TD> <TD><HTML:TEXT property=&quot;zip&quot; size =&quot;9&quot; maxlength =&quot;9&quot; /></TD></TR> <TR><TD ALIGN=CENTER><html:submit property=&quot;action&quot; value =&quot;Save&quot;/></TD> <TD><html:reset property=&quot;action&quot; value =&quot;Reset&quot;/></TD></TR> </TABLE> </HTML:FORM> </BODY> </HTML:HTML>
  • 45. Logic Tag Library Tags Wraps content that is conditionally processes based on whether a specified object’s value contains, starts with, or ends with a specified constant value. match Wraps content that is conditionally processes based on whether a specified object’s value is less than specified constant value lessThan Wraps content that is conditionally processes based on whether a specified object’s value is less than or equal to specified constant value. lessEqual Wraps content that is repeated for each element of a specified collection. iterate Wraps content that is conditionally processes based on whether a specified object’s value is greater than specified constant value. greaterThan Wraps content that is conditionally processes based on whether a specified object’s value is greater than or equal to specified constant value. greaterEqual Looks up a forward from the struts configuration file and processes it. forward Wraps content that is conditionally processes based on whether a specified object’s value equals a specified constant value. equal Wraps content that is conditionally processes based on whether the specified object is null or contains an empty (zero-length) String . empty
  • 46. Composes a URL to another page and then redirects to it. redirect Wraps content that is conditionally processes based on whether a specified object exists. present Wraps content that is conditionally processes based on whether a specified object does not exist. notPresent Wraps content that is conditionally processes based on whether a specified object’s value does not contain, start with, or end with a specified constant value. notMatch Wraps content that is conditionally processes based on whether the specified object is not equal to a specified constant value . notEqual Wraps content that is conditionally processes based on whether the specified object is non -null and does not contain an empty String . notEmpty Wraps content that is conditionally processes based on whether Struts’ org.apache.struts.Action.ActionErrors or org.apache.struts.action. .ActionMessages object has any errors or messages in it, respectively messagesPresent Wraps content that is conditionally processes based on whether Struts’ org.apache.struts.Action.ActionErrors or org.apache.struts.action. .ActionMessages object does not have any errors or messages in it. messagesNotPresent
  • 47. Nested Tag Library Tags Nesting-enabled version of the Logic Tag Library’s iterate tag. iterate Nesting-enabled version of the HTML Tag Library’s img tag. img Nesting-enabled version of the HTML Tag Library’s image tag. image Nesting-enabled version of the HTML Tag Library’s hidden tag. hidden Nesting-enabled version of the Logic Tag Library’s lessEqual tag. lessEqual Nesting-enabled version of the Logic Tag Library’s greaterThan tag. greaterThan Nesting-enabled version of the Logic Tag Library’s greaterEqual tag. greaterEqual Nesting-enabled version of the HTML Tag Library’s form tag. form Nesting-enabled version of the HTML Tag Library’s file tag. file Nesting-enabled version of the HTML Tag Library’s errors tag. errors Nesting-enabled version of the Logic Tag Library’s equal tag. equal Nesting-enabled version of the Logic Tag Library’s empty tag. empty Nesting-enabled version of the Bean Tag Library’s define tag. define Nesting-enabled version of the HTML Tag Library’s checkbox tag. checkbox
  • 48. Nesting-enabled version of the HTML Tag Library’s options tag. options Nesting-enabled version of the Logic Tag Library’s notPresent tag. notPresent Nesting-enabled version of the Logic Tag Library’s notMatch tag. notMatch Nesting-enabled version of the Logic Tag Library’s notEqual tag. notEqual Nesting-enabled version of the Logic Tag Library’s notEmpty tag. notEmpty Defines a logical level in a nesting hierarchy and associates an object with it that all of its nested tags will be relative to. nest Nesting-enabled version of the HTML Tag Library’s multibox tag. multibox Nesting-enabled version of the Logic Tag Library’s messagesPresent tag. messagesPresent Nesting-enabled version of the Logic Tag Library’s messagesNotPresent tag. messagesNotPresent Nesting-enabled version of the HTML Tag Library’s messages tag. messages Nesting-enabled version of the Bean Tag Library’s message tag. message Nesting-enabled version of the Logic Tag Library’s match tag. match Nesting-enabled version of the HTML Tag Library’s link tag. link Nesting-enabled version of the Logic Tag Library’s lessThan tag. lessThan
  • 49. Renders or creates a JSP scripting variable for a string representation of the object related to the current nesting level. writeNesting Nesting-enabled version of the Bean Tag Library’s write tag. write Nesting-enabled version of the HTML Tag Library’s textarea tag. textarea Nesting-enabled version of the HTML Tag Library’s text tag. text Nesting-enabled version of the HTML Tag Library’s submit tag. submit Nesting-enabled version of the Bean Tag Library’s size tag. size Nesting-enabled version of the HTML Tag Library’s select tag. select Defines the root object of a nested hierarchy of objects. root Nesting-enabled version of the HTML Tag Library’s radio tag. radio Nesting-enabled version of the Logic Tag Library’s present tag. present Nesting-enabled version of the HTML Tag Library’s password tag. password Nesting-enabled version of the HTML Tag Library’s optionsCollection tag. optionsCollection
  • 50.
  • 51. Bean Tags   Tag Name Description 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 JspWriter.
  • 52. Bean Tag Example <table border=&quot;2&quot;> <tr> <th align=&quot;left&quot;><bean:message key=“imagebroker.lob”/></th> <th align=&quot;left&quot;><bean:message key=“imagebroker.unitnbr”/></th> <th align=&quot;left&quot;><bean:message key=“imagebroker.onbase_dns”/></th> </tr> <logic:iterate id=&quot;image&quot; property=&quot;collection&quot; name=&quot;ImageLocationListForm&quot;> <tr> <td><a href=&quot;ImageLocationListForm.do?lob=<bean:write name='image' property='lob'/> &unitnbr=<bean:write name='image' property='unitnbr'/> &onbase_dns=<bean:write name='image' property='onbase_dns'/>&quot; > <bean:write name=&quot;image&quot; property=&quot;lob&quot;/></a></td> <td><bean:write name=&quot;image&quot; property=&quot;unitnbr&quot;/></td> <td><bean:write name=&quot;image&quot; property=&quot;onbase_dns&quot;/></td> </tr> </logic:iterate> </table>
  • 53.
  • 54.
  • 55.
  • 56. Logic Tags   Tag Name Description 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 requested variable is greater than or equal to 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 requested variable is greater than or equal to 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 specified value is an appropriate substring of requested variable. messagesNotPresent Generate the nested body content of this tag if the specified message is not present in this request. messagesPresent Generate the nested body content of this tag if the specified message is present in this request. notEmpty Evaluate the nested body content of this tag if the requested variable is neither null nor an empty string. 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 tag if specified value not an appropriate substring of 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
  • 57. Logic Tags - Example <html:html> <head> <title><bean:message key=&quot;imagebrokerlink.title&quot;/></title> <META name=&quot;GENERATOR&quot; content=&quot;IBM WebSphere Studio&quot;> </head> <body> <html:form action=&quot;/ImageLocationForm&quot; > <center> <font size=3> <br> <b> <logic:notEqual property=&quot;action&quot; name=&quot;ImageLocationForm&quot; value=&quot;Insert&quot;> <bean:message key=&quot;imagelocationdetail.title&quot;/> </logic:notEqual> <logic:equal property=&quot;action&quot; name=&quot;ImageLocationForm&quot; value=&quot;Insert&quot;> <bean:message key=&quot;imagelocationinsert.title&quot;/> </logic:equal> … …
  • 58.
  • 59.
  • 60. Custom Tags <%@ taglib uri=&quot;WEB-INF/imagebroker.tld&quot; prefix=&quot;broker&quot; %> <table width=750 cellspacing=0 cellpadding=2 border=2 > <tr> <td><broker:form lob='<%=test.getLob()%>' unitnbr='<%=test.getUnitnbr()%>' userid='<%=test.getUserid()%>' > <broker:doctype value=&quot;Invoice&quot;/> <broker:keyword name=&quot;CompanyNbr&quot; value=&quot;55555&quot;/> <broker:keyword name=&quot;PONbr&quot; value=&quot;M12345&quot;/> <broker:constraint name=&quot;FromDate&quot; value=&quot;02/02/2002&quot;/> <broker:constraint name=&quot;ToDate&quot; value=&quot;02/28/2002&quot;/> Image Broker Link Test </broker:form> </td> </tr> </table>
  • 61. Custom Tags – tld File <tag> <name>doctype</name> <tagclass>com.pri.brokertag.ImageBrokerDoctype</tagclass> <attribute> <name>value</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag>
  • 62. Custom Tags – Tag Class public class ImageBrokerDoctype extends TagSupport { private String value = null; public int doStartTag() throws JspException { Hashtable ht = null; String keyword_count = null; int iCnt = 0; HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); ht = (Hashtable) request.getAttribute(&quot;keyword_parms&quot;); keyword_count = (String) request.getAttribute(&quot;queryobject_count&quot;); iCnt ++; ht.put(&quot;QueryObject&quot; + iCnt, value); request.setAttribute(&quot;keyword_parms&quot;, ht); request.setAttribute(&quot;queryobject_count&quot;, new String(new Integer(iCnt).toString())); return EVAL_PAGE; } }
  • 64.
  • 65.
  • 66. Struts-config.xml <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; ?> <!DOCTYPE struts-config PUBLIC &quot;-//Apache Software Foundation//DTD Struts Configuration 1.0//EN&quot; &quot;http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd&quot;> <struts-config> <!-- ========== Form Bean Definitions =================================== --> <form-beans> <form-bean name=&quot;CryptForm&quot; type=&quot;com.pri.imagebrokerWeb.CryptForm&quot; /> </form-beans> <!-- ========== Global Forward Definitions ============================== --> <global-forwards> <forward name=&quot;start&quot; path=&quot;/index.html&quot;/> </global-forwards> <!-- ========== Action Mapping Definitions ============================== --> <action-mappings> <action path=&quot;/CryptForm&quot; type=&quot;com.pri.imagebrokerWeb.CryptAction&quot; name=&quot;CryptForm&quot; scope=&quot;request&quot; input=&quot;/pgCrypt.jsp&quot;> <forward name=&quot;encrypt&quot; path=&quot;/pgCryptDisplay.jsp&quot;/> </action> </action-mappings> </struts-config>
  • 68.
  • 69. Web.xml File <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN&quot; &quot;http://java.sun.com/j2ee/dtds/web-app_2_2.dtd&quot;> <web-app id=&quot;WebApp&quot;> <display-name>imagebrokerWeb</display-name> <!-- Action Servlet Configuration --> <servlet id=&quot;Servlet_1&quot;> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>application</param-name><param-value>imagebrokerWeb</param-value> </init-param> <init-param> <param-name>config</param-name><param-value>WEB-INF/struts-config.xml</param-value> </init-param> </servlet>
  • 70. Web.xml File - continued <!-- Action Servlet Mapping --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- The Welcome File List --> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list>
  • 71. Web.xml File - continued <!-- Struts Tag Library Descriptors --> <taglib> <taglib-uri>WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> <taglib> <taglib-uri>WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> <taglib> <taglib-uri>WEB-INF/struts-logic.tld</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib> </web-app>
  • 73. Application.properties File error.cryptvalue.required=<li>You must enter some text.</li> error.lob.required=<li>You must enter the Line of Business.</li> error.unitnbr.required=<li>You must enter the Unit Number.</li> error.onbase_dns.required=<li>You must enter the OnBase DNS.</li> imagebroker.linkname=Project Refinery, Inc. imagebroker.title=pri Image Broker imagebrokerlink.title=pri Image Broker Link Test imagelocationlist.title=Image Location List imagelocationdetail.title=Image Location Detail imagelocationinsert.title=Image Location Insert errors.header= errors.footer=
  • 75.
  • 76.

Notas do Editor

  1. A user sitting at a browser clicks a button, link, or types in a url. A Struts Servlet receives that request. It normally hands over the request to a FormAction class. The FormAction class is responsible for validating any form input. Control is then passed on to an Action class. It’s the responsibility of the Action class to call any Model components, such as classes responsible for updating information in a database. The final step is typically to forward to another JSP, thus a response being sent back to the browser.
  2. The default Servlet controller is org.apache.struts.action.ActionServlet. This Servlet can be extended by your application, but typically there is no need to. Note that this ONE Servlet controls all of your Struts application. Your application will consist of any number of Java Server Pages. These pages could be list pages, form pages, or any other type of web page. Your application will normally consist of other classes that make up the Model components. These classes can be either standard Java classes of EJB’s, or a combination of both.
  3. In using WSAD and Struts, you’ll notice that once you start your application, the web.xml file is read, loads the ActionServlet, which then reads the struts-config.xml file, which has references to all of your form beans (ActionForms), Action beans, and the navigation your application will use.
  4. Many requirements documents used for building web applications focus on the View . However, you should ensure that the processing required for each submitted request is also clearly defined from the Model&apos;s perspective. In general, the developer of the Model components will be focusing on the creation of JavaBeans classes that support all of the functional requirements. The precise nature of the beans required by a particular application will vary widely depending on those requirements, but they can generally be classified into several categories.
  5. EJB’s are the industry standard for Java Model components. With that said, you’ll find that you don’t always use them. There is nothing to prevent you from connecting to a database, performing a SQL statement, and then returning the result set from any type of Java class. In grammatical terms, we might think about state information as nouns (things) and actions as verbs (changes to the state of those things).
  6. Within a web-based application, JavaBeans can be stored in (and accessed from) a number of different collections of &amp;quot;attributes&amp;quot;. Each collection has different rules for the lifetime of that collection, and the visibility of the beans stored there. Together, the rules defining lifetime and visibility are called the scope of those beans. The Java Server Pages (JSP) Specification defines scope choices using the above terms (with the equivalent Servlet API concept defined in parentheses):
  7. You should note that a &amp;quot;form&amp;quot;, in the sense discussed here, does not necessarily correspond to a single JSP page in the user interface. It is common in many applications to have a &amp;quot;form&amp;quot; (from the user&apos;s perspective) that extends over multiple pages. Think, for example, of the wizard style user interface that is commonly used when installing new applications. Struts encourages you to define a single ActionForm bean that contains properties for all of the fields, no matter which page the field is actually displayed on. Likewise, the various pages of the same form should all be submitted to the same Action Class. If you follow these suggestions, the page designers can rearrange the fields among the various pages, often without requiring changes to the processing logic.
  8. Although business logic should not be directly included in the ActionForm class, it is a good idea to call Java Beans or Enterprise Java Beans that contain the business logic from your ActionForm. If an error is then identified by calling the business logic, an ActionError can easily be generated.
  9. When defining your getter and setter methods, make sure the names match with what were specified within the form on the Java Server Page. For example, if you defined a text field within your form named firstName, you should define a private String property with a getFirstName() and setFirstName() methods.
  10. For small scale systems, or for state information that need not be kept for a long period of time, a set of system state beans may contain all the knowledge that the system ever has of these particular details. Or, as is often the case, the system state beans will represent information that is stored permanently in some external database (such as a CustomerBean object that corresponds to a particular row in the CUSTOMERS table), and are created or removed from the server&apos;s memory as needed. Entity Enterprise JavaBeans are also used for this purpose in large scale applications.
  11. When writing business logic beans, there should never be any reference to resources that are only available within a web application server environment. It would NOT be a good idea to pass something like the HttpServletRequest block to a business logic bean. This would limit the use of that business logic bean to only be used within a web project. The idea is to have the business logic bean available to ANY type of application.
  12. One of the reasons to place business logic into an EJB is for scalability. If a particular business logic bean was referenced in numerous applications as a regular Java Bean, this would take additional resources. If that business logic is written within an EJB, it would only be instantiated once.
  13. Although Struts provides a mechanism within the struts-config.xml file to define data sources, WebSphere provides a similar mechanism which also includes a more sophisticated connection pool.
  14. This unit focuses on the task of building the View components of the application, which will primarily be created using Java Server Pages (JSP) technology. In particular, Struts provides support for building internationalized applications, as well as for interacting with input forms.
  15. With the use of a property files, Struts has the capability to handle multiple languages. Instead of placing text directly within your Java Server Pages, a Struts bean tag is used to get that information from a property file. If for example you need to also support Spanish, a second property file would be defined with the same name as the original with an “_es” appended to the name. This property file would have the Spanish text. The browser recognizes what language the user has set for their default, and Struts uses that to know which property file to reference.
  16. When you configure the controller Servlet in the web application deployment descriptor, one of the things you will need to define in an initialization parameter is the base name of the resource bundle for the application. &lt;servlet&gt; &lt;servlet-name&gt;action&lt;/servlet-name&gt; &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;application&lt;/param-name&gt; &lt;param-value&gt;MyResources&lt;/param-value&gt; &lt;/init-param&gt; &lt;.../&gt; &lt;/servlet&gt;
  17. At one time or another, most web developers have built forms using the standard capabilities of HTML, such as the &lt;input&gt; tag. Users have come to expect interactive applications to have certain behaviors, and one of these expectations relates to error handling -- if the user makes an error, the application should allow them to fix just what needs to be changed -- without having to re-enter any of the rest of the information on the current page or form. Fulfilling this expectation is tedious and cumbersome when coding with standard HTML and JSP pages. For example, an input element for a username field might look like this (in JSP): &lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; value=&amp;quot;&lt;%= loginBean.getUsername() %&gt;&amp;quot;/&gt; which is difficult to type correctly, confuses HTML developers who are not knowledgeable about programming concepts, and can cause problems with HTML editors. Instead, Struts provides a comprehensive facility for building forms, based on the Custom Tag Library facility of JSP 1.1. The case above would be rendered like this using Struts: &lt;html:text property=&amp;quot;username&amp;quot;/&gt; with no need to explicitly refer to the JavaBean from which the initial value is retrieved. That is handled automatically by the framework. HTML forms are sometimes used to upload other files. Most browsers support this through a &lt;input type=&amp;quot;file&amp;quot;&gt; element, that generates a file browse button, but it&apos;s up to the developer to handle the incoming files. Struts handles these &amp;quot;multipart&amp;quot; forms in a way identical to building normal forms.
  18. The tag libraries should first be referenced within the web.xml file. The taglib directive within the Java Server Page typically references the uri specified within the web.xml file. There are two ways to use the error tags. You can have one place within your Java Server Page to show all errors, or you can place an error tag close to each field that may result in an error condition. These error conditions are created within your ActionForm class.
  19. Within the &lt;form-beans&gt; section in the struts-config.xml file, you would define a form tag like the following: &lt; form-bean name = &amp;quot;CustomerFormBean&amp;quot; type = &amp;quot;com.pri.javaTraining.CustomerForm&amp;quot; /&gt; This &lt;form-bean&gt; tag is also referenced within the &lt;action-mappings&gt; tag in the struts-config.xml file, like the following: &lt; action path = &amp;quot;/CustomerAction&amp;quot; type = &amp;quot;com.pri.javaTraining.CustomerAction&amp;quot; name = &amp;quot;CustomerFormBean&amp;quot; scope = &amp;quot;request&amp;quot; input = &amp;quot;/pgcustomer.jsp&amp;quot; &gt; &lt; forward name = &amp;quot;Save&amp;quot; path = &amp;quot;/pgindex.jsp&amp;quot; /&gt; &lt; forward name = &amp;quot;Add Account&amp;quot; path = &amp;quot;/pgaddaccount.jsp&amp;quot; /&gt; &lt; forward name = &amp;quot;Cancel&amp;quot; path = &amp;quot;/pgindex.jsp&amp;quot; /&gt; &lt;/ action &gt;
  20. The validate() method has the following options: Perform the appropriate validations and find no problems -- Return either null or a zero-length ActionErrors instance, and the controller servlet will proceed to call the perform() method of the appropriate Action class. Perform the appropriate validations and find problems -- Return an ActionErrors instance containing ActionError &apos;s, which are classes that contain the error message keys (into the application&apos;s MessageResources bundle) that should be displayed. The controller servlet will store this array as a request attribute suitable for use by the &lt;html:errors&gt; tag, and will forward control back to the input form (identified by the input property for this ActionMapping ). As mentioned earlier, this feature is entirely optional. The default implementation of the validate() method returns null , and the controller servlet will assume that any required validation is done by the action class. One common approach is to perform simple, prima facia validations using the ActionForm validate() method, and then handle the &amp;quot;business logic&amp;quot; validation from the Action.
  21. The Controller portion of the application is focused on receiving requests from the client (typically a user running a web browser), deciding what business logic function is to be performed, and then delegating responsibility for producing the next phase of the user interface to an appropriate View component. In Struts, the primary component of the Controller is a servlet of class ActionServlet . This servlet is configured by defining a set of ActionMappings . An ActionMapping defines a path that is matched against the request URI of the incoming request, and usually specifies the fully qualified class name of an Action class. All Actions are subclassed from org.apache.struts.action.Action . Actions encapsulate the business logic, interpret the outcome, and ultimately dispatch control to the appropriate View component to create the response.
  22. org.apache.struts.action.ActionServlet is the default Servlet that is provided with Struts. This Servlet can be used, or it can be extended. If extended, the extended version should be defined in the web.xml file. For smaller applications, ActionServlet typically provides the necessary functionality. For larger applications, it is typically extended.
  23. It is not always necessary to create an Action class for each form within your project. For smaller applications one Action class could provide the necessary functionality for the entire project. However, it is a good practice to create a new Action class for each form. So for a Java Server Page that has a form, an extension of the ActionForm class would be created, and an extension of the Action class would also be created. This allows for easier maintenance. It is also a widely adopted approach within the Struts development community to place a form on EVERY Java Server Page. Even list pages would have a form defined on them. This gives the maximum flexibility to the developer. This approach allows for more flexibility on navigation.
  24. The second method is the one used by WebSphere.
  25. If is NOT a good practice to “hard code” the name of the Java Server Page that you are forwarding to. Within Struts all Java Server Pages should be specified within the struts-config.xml file. For a particular Action class, multiple forward tags may be specified. Here’s an example: &lt; action path = &amp;quot;/CustomerAction&amp;quot; type = &amp;quot;com.pri.javaTraining.CustomerAction&amp;quot; name = &amp;quot;CustomerFormBean&amp;quot; scope = &amp;quot;request&amp;quot; input = &amp;quot;/pgcustomer.jsp&amp;quot; &gt; &lt; forward name = &amp;quot;Save&amp;quot; path = &amp;quot;/pgindex.jsp&amp;quot; /&gt; &lt; forward name = &amp;quot;Add Account&amp;quot; path = &amp;quot;/pgaddaccount.jsp&amp;quot; /&gt; &lt; forward name = &amp;quot;Cancel&amp;quot; path = &amp;quot;/pgindex.jsp&amp;quot; /&gt;
  26. Below is a very simple example of an Action class’ perform method: public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { /** Get a handle to the StrutsInputForm */ StrutsInputForm strutsForm = (StrutsInputForm) form; /** Get the action from the form */ String action = strutsForm.getAction(); /** Forward control to the specified success URI */ return (mapping.findForward(action)); }
  27. Only define variables within the perform() method, or within methods that you’ve added to the Action class.
  28. A common approach to logging is to use another of the Jakarta open source modules named Log4j: http://jakarta.apache.org/log4j/docs/index.html
  29. Below is an example of an ActionMapping implementation: &lt; action path = &amp;quot;/CustomerAction&amp;quot; type = &amp;quot;com.pri.javaTraining.CustomerAction&amp;quot; name = &amp;quot;CustomerFormBean&amp;quot; scope = &amp;quot;request&amp;quot; input = &amp;quot;/pgcustomer.jsp&amp;quot; &gt; &lt; forward name = &amp;quot;Save&amp;quot; path = &amp;quot;/pgindex.jsp&amp;quot; /&gt; &lt; forward name = &amp;quot;Add Account&amp;quot; path = &amp;quot;/pgaddaccount.jsp&amp;quot; /&gt; &lt; forward name = &amp;quot;Cancel&amp;quot; path = &amp;quot;/pgindex.jsp&amp;quot; /&gt;
  30. The two important elements are: &lt;form-beans&gt; This section contains your form bean definitions. You use a &lt;form-bean&gt; element for each form bean, which has the following important attributes: name : A unique identifier for this bean, which will be used to reference it in corresponding action mappings. Usually, this is also the name of the request or session attribute under which this form bean will be stored. type : The fully-qualified Java classname of your form bean. &lt;action-mappings&gt; This section contains your action definitions. You use an &lt;action&gt; element for each of your actions you would like to define. Each action element requires the following attributes to be defined: path : The application context-relative path to the action type : The fully qualified java classname of your Action class name : The name of your &lt;form-bean&gt; element to use with this action
  31. Below is an example of a typical &lt;form-beans&gt; section: &lt; form-beans &gt; &lt;!-- Struts Example form bean --&gt; &lt; form-bean name = &amp;quot;StrutsInputFormBean&amp;quot; type = &amp;quot;org.struts.example.StrutsInputForm&amp;quot; /&gt; &lt; form-bean name = &amp;quot;StrutsDisplayFormBean&amp;quot; type = &amp;quot;org.struts.example.StrutsDisplayForm&amp;quot; /&gt; &lt;/ form-beans &gt;
  32. Below is an example of a typical &lt; action-mappings &gt; section: &lt; action-mappings &gt; &lt;!-- StrutsExample --&gt; &lt; action path = &amp;quot;/StrutsInputPath&amp;quot; type = &amp;quot;org.struts.example.StrutsInputAction&amp;quot; name = &amp;quot;StrutsInputFormBean&amp;quot; scope = &amp;quot;request&amp;quot; input = &amp;quot;/PgInput.jsp&amp;quot; &gt; &lt; forward name = &amp;quot;Next&amp;quot; path = &amp;quot;/PgDisplay.jsp&amp;quot; /&gt; &lt;/ action &gt; &lt; action path = &amp;quot;/StrutsDisplayPath&amp;quot; type = &amp;quot;org.struts.example.StrutsDisplayAction&amp;quot; name = &amp;quot;StrutsDisplayFormBean&amp;quot; scope = &amp;quot;request&amp;quot; input = &amp;quot;/PgDisplay.jsp&amp;quot; &gt; &lt;/ action &gt; &lt;/ action-mappings &gt;
  33. This is a section that will probably NOT be used when running an application server such as WebSphere. WebSphere has a much more sophisticated connection pooling mechanism.
  34. We’re going to go over both the struts-config.xml and the web.xml files in later chapters.
  35. You can find links to each tag library at the following URL under the Developer’s Guide: http://jakarta.apache.org/struts/doc-1.0.2/index.html. When developing Java Server Pages, a developer has the capability to imbed Java code. However, this is considered a bad approach. Through the use of the Struts tag libraries, and custom tag libraries, a developer should be able to create Java Server Pages without ANY Java code imbedded. Actually a widely accepted practice is to have a Business Analyst with web page design experience to create the Java Server Page. Once they have the “look and feel” completed, they would turn that Java Server Page over to the developer, who would add whatever additional capabilities that were necessary.
  36. One important item to point out about HTML is that the developer has no control over the HTML tags. They only serve very specific purposes. The developer has to develop within those limitations. One of the major advantages of using tab libraries is that you’re NOT constrained with those limitations.
  37. Notice the &lt;html:text tag. It’s similar to the &lt;input type=“text” html tag. One major difference is the property attribute, and this is important. The name you specify in the property tag, is what Struts uses to know which getter and setter methods to call. For example, if the property name is “state”, the getter method would be getState(), and the setter method would be setState. If a property name was “firstName”, the getter method would be getFirstName(), and the setter method would be setFirstName().
  38. Much of the power of JavaServer Pages (JSP) technology comes from the simple and powerful mechanisms by which the servlet that is generated automatically from your JSP source page can interact with JavaBeans that represent the computational state of your application. In standard JSP pages, the &lt;jsp:useBean&gt; tag is used create a bean (if necessary), as well as a &amp;quot;scripting variable&amp;quot; that can be used within scriptlets to refer to these beans.
  39. Two of the above tags that you’ll use frequently are the “message” and “write” tags. You use the “message” tag to retrieve text messages from the application resources file (whatever.properties). The “write” tag is used to display information that has either been entered or been retrieved from a database.
  40. This JSP shows the use of the bean message and bean write tags. On the bean message tag, you specify a key name. This key name references an entry into your application resources file. On the bean write tag, you specify a name attribute which references the id of the iterate tag. You also specify a property name which references a getter method on the form bean that’s referenced by the “ImageLocationListForm”.
  41. One question that may come up at this point is why not just put Java code into your JSP? The answer to that question is answered by referring back to the roles we’ve defined for doing this kind of development. The idea is to have someone that is not a programmer be able to create and maintain the JSP’s. This allows someone that has creative skills to create attractive and easy to use web pages. This also frees up the developer from what they normally consider tedious and time consuming tasks.
  42. For further information on the Logic Tags, visit: http://jakarta.apache.org/struts/api/org/apache/struts/taglib/logic/package-summary.html#package_description
  43. Many of the tags in this tag library will throw a JspException at runtime when they are utilized incorrectly (such as when you specify an invalid combination of tag attributes). JSP allows you to declare an &amp;quot;error page&amp;quot; in the &lt;%@ page %&gt; directive. If you wish to process the actual exception that caused the problem, it is passed to the error page as a request attribute under key org.apache.struts.action.EXCEPTION .
  44. For further information on the Logic Tags, visit: http://jakarta.apache.org/struts/api/org/apache/struts/taglib/logic/package-summary.html#package_description
  45. Notice the &lt;logic:notEqual tag. It has a property attribute that references a getter method, a name attribute that references a form, and a value attribute that is what is going to be checked for a not equal condition. If the value is not equal to “Insert” in this example, the next line will be shown. The next line uses the bean message tag, and will display a title indicating this is a Detail page. Also notice the closing &lt;/logic:notEqual&gt; tag. The next line shows a &lt;logic:equal tag. If the value does equal “Insert”, a title of “Insert” is displayed. By using this approach we were able to use the same JSP for both a page to perform updates to existing data, and the capability to insert new records.
  46. The Template library supplies tags that are useful for creating dynamic JSP templates for pages which share a common format.
  47. For further information on Template Tags, visit: http://jakarta.apache.org/struts/api/org/apache/struts/taglib/template/package-summary.html#package_description
  48. This JSP shows the use of custom tags. Note the &lt;broker:form&gt; tag. This tag has other customer tags nested within it. The purpose of this link tag is to take the values of the attributes passed to it, along with the values of the other custom tags nested within it, and create an XML document that can be passed to another web server. It actually encrypts the XML document, and embeds that data within a form with a submit button. The user is then able to click the button or link and they’re directed to one of the image servers, and an image is displayed. Below is the html source from what gets generated from the custom tags above: &lt;form name=&amp;quot;ibs_form5&amp;quot; method=&amp;quot;POST&amp;quot; action=&amp;quot;http://corpiisimgdv01.pri.corpad.net/devibroker/broker_process.asp&amp;quot; target=&amp;quot;_blank&amp;quot;&gt; &lt;a href=javascript:document.forms.ibs_form5.submit()&gt;EOBs/REMITS (via Doc Handle)&lt;/a&gt;&lt;br&gt; &lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;packet&amp;quot; value=&amp;quot;E25A7C35ECBD975BCBCBED16C10EB6BE9343A40B022DC2FF774ABAD53D94293FB1780D4D4D9489B71389E0824A7B13708AEFA66BA3698DAA255A4B85741B8ECC45C0CB1F3A3261C8230FB74253AB0BC326320DFBE699B347C5CD240BA4DE1EC1A07BA20442DC9430922CE95749B6D795CF8359691F5CC91A52169FF3B6403B4D97ED09D52540E3A83B7479770300A527CA040B43F5F24CFE17D8477D856FA6106575A9F41FD95AD4D717147A9A07A45D7AE45CB22A4F6482F2BB6A1B659B725EA74FE7C59AC24D5F0069D26956144BCC54FCE5D34C15FEFBD22CEEC6E0A85D1207EBD70B8B9397ACC49A4572F0F3B5D35D559CEC9BF6ED8A94E67AAAE54DCF1D9BAD720851BCE96F0263495F0A76B65F9D1A0F9EA6454B7624DE0EEE4B9B5B69&amp;quot;&gt; &lt;/form&gt;
  49. This displays what is needed in creating a “tld” file. You define what the name of the tag is, what Java class is responsible for processing the tag, and whatever attributes are needed to support the tag.
  50. This displays a Tag class. A typical tag class has a doStartTag() and a doEndTag() method. You decide which of these you need to override. Sometimes it will be both.
  51. How does the controller Servlet learn about the mappings you want? Struts includes a Digester module that is capable of reading an XML-based description of the desired mappings, creating the appropriate objects along the way.
  52. The two important elements are: &lt;form-beans&gt; This section contains your form bean definitions. You use a &lt;form-bean&gt; element for each form bean, which has the following important attributes: name : A unique identifier for this bean, which will be used to reference it in corresponding action mappings. Usually, this is also the name of the request or session attribute under which this form bean will be stored. type : The fully-qualified Java classname of your form bean. &lt;action-mappings&gt; This section contains your action definitions. You use an &lt;action&gt; element for each of your actions you would like to define. Each action element requires the following attributes to be defined: path : The application context-relative path to the action type : The fully qualified java classname of your Action class name : The name of your &lt;form-bean&gt; element to use with this action
  53. Notice the &lt;form-beans&gt; tag section. Within this section you use the &lt;form-bean tag to assign a name to your form bean, and in the type attribute you put the fully qualified class name. This class is always a descendent of ActionForm. Notice the &lt;global-forwards&gt; tag section. Within this section you use the &lt;forward tag and assign a value to the name attribute. The name attribute is referenced by the Action class to determine if the action the user performed is this name, and if so it forwards to the value specified in the path attribute. In this example if the user clicked a button where the value of the button was “start”, the user would be sent to the index.html page. Notice the &lt;action-mappings&gt; tag section. Within this section you use the &lt;action tag and assign several values. The first attribute is path, and is referenced by acion=“” within a JSP form. The next attribute (type), describes the name of the Action class. This class referenced here is always a decendent of org.apache.
  54. The web.xml file is not something only used for Struts. It’s used in all J2EE web applications. It does have references to things that are Struts specific though.
  55. Note that a web.xml file is not unique to Struts. When using WSAD and generating a web project, a web.xml file is automatically generated. However, it does not contain much that is useful. Typically a developer copies a web.xml file from an existing Struts based project, and then modifies it.
  56. Note the line that has the &lt;servlet-class&gt; tag. It references the org.apache.struts.action.ActionServlet class. If you extend this class due to the necessity to provide additional functionality, you will need to reference your extended class here. Also not the &lt;param-name&gt; tag with the value of application. The following &lt;param-value&gt; tag is where you reference your projects property file.
  57. Note the &lt;welcome-file&gt; tag. The value specified here is the start page of your application. This can either be an html file, or a Java Server Page. There are two common approaches to defining the URLs that will be processed by the controller Servlet -- prefix matching and extension matching. An appropriate mapping entry for each approach is described below. Prefix matching means that you want all URLs that start (after the context path part) with a particular value to be passed to this Servlet. Such an entry might look like this: &lt;servlet-mapping&gt; &lt;servlet-name&gt;action&lt;/servlet-name&gt; &lt;url-pattern&gt;/execute/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; which means that a request URI to match the /logon path described earlier might look like this: http://www.mycompany.com/myapplication/execute/logon where /myapplication is the context path under which your application is deployed. Extension mapping, on the other hand, matches request URIs to the action servlet based on the fact that the URI ends with a period followed by a defined set of characters. For example, the JSP processing servlet is mapped to the *.jsp pattern so that it is called to process every JSP page that is requested. To use the *.do extension (which implies &amp;quot;do something&amp;quot;), the mapping entry would look like this: &lt;servlet-mapping&gt; &lt;servlet-name&gt;action&lt;/servlet-name&gt; &lt;url-pattern&gt;*.do&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; and a request URI to match the /logon path described earlier might look like this: http://www.mycompany.com/myapplication/logon.do
  58. An entry defining the Struts tag library must be included in the web.xml file. If any custom tag libraries are used they must also be defined here.
  59. Application Resource or property files are not unique to Struts applications. However, with the internationalization support built into Struts, they are used more.
  60. Above is an example of an application resources property file. This file can contain any number of items. The one above shows examples of error messages, and text values used for things such as a title in your Java Server Page or the text on a button.
  61. Many resources are available on the Internet. Currently there is only one published book on Struts, and it is not recommended by the author of these slides.
  62. They’re many sites with Struts information. The third bullet item above displays a link to a page on the main Struts site which has links to many other sites. One other item worth mentioning is that IBM uses Struts. Some of the example projects included with WSAD use Struts.