SlideShare una empresa de Scribd logo
1 de 50
Java II
J2EE Struts
Struts: Introduction
•  Once you’ve coded a lot of JSP applications, you find yourself doing a lot of repetitive things. •  Also, if you have a hard-coded link scattered around a lot of JSPs, the first time you need to  change  that link you discover a special kind of agony.  •  Struts was designed to solve that problem and a few others.  •  Struts is about moving code to xml property files.  Struts:  Introduction * * This lecture was based on “ Struts in Action ” by Ted Husted ISBN 1-930110-50-2
•  Struts is based on the MVC or Model-View-Controller design pattern. Struts:  Introduction
•  Under Struts the work of operating a web application is divided up: ActionServlet —this Struts component controls navigation. Action —this Struts component controls business logic. Struts:  Introduction
•  Here’s the process: 1.) An  ActionServlet  receives a request from the container. 2.) The  ActionServlet  collects the information in the request. 3.) Using the request URI, the  ActionServlet  tries to  match the URI  with a so-called  Action  class. 4.) Whichever  Action  class is passed the request will take the correct course of action. Struts:  Introduction
•  The preceding is just a general idea of how it works. •  Struts uses the following Java classes to work its magic: ActionForm ActionServlet ActionMapping ActionForward Action •  In addition to these, Struts places a lot of information in xml configuration files: strut-config.xml Struts:  Introduction
We will explore these in depth, but here’s a thumbnail version  of each: ActionForm —Collects  form  data from HTML page. ActionServlet —Controls everything. ActionMapping —Helps when deciding where to go. ActionForward —Where to send request Action —Called to do business logic. Struts:  Introduction
Struts: ActionForm
•  A Web Application is driven by HTML pages.  •  A typical WebApp contains text fields in a  FORM . •  To extract information from this page, we use the  NAME .  Struts:  ActionForm <HTML> <HEAD><TITLE>Simple JSP</TITLE></HEAD> <BODY> <FORM METHOD=&quot;POST&quot; ACTION=&quot;/TestServlet&quot;> <BR>Username: <INPUT TYPE=&quot;text&quot;  NAME =&quot; user &quot; VALUE=&quot;&quot;> <BR>Password: <INPUT TYPE=&quot;text&quot;  NAME =&quot; pass &quot; VALUE=&quot;&quot;> </FORM> </BODY> </HTML>
•  Given the HTML page we see below, we could pull out the value of the tag with the  NAME  of  user  by using the following code in a Servlet’s  doPost()  method: String userField = request.getParameter(&quot; user &quot;); Struts:  ActionForm <HTML> <HEAD><TITLE>Simple JSP</TITLE></HEAD> <BODY> <FORM METHOD=&quot;POST&quot; ACTION=&quot;/SomeServlet&quot;> <BR>Username: <INPUT TYPE=&quot;text&quot;  NAME =&quot; user &quot; VALUE=&quot;&quot;> <BR>Password: <INPUT TYPE=&quot;text&quot;  NAME =&quot; pass &quot; VALUE=&quot;&quot;> </FORM> </BODY> </HTML>
•  However, with any fairly large page, this becomes tedious. •  A better way is to use a  JavaBean . •  Using a  JavaBean , we place all the data in the bean on the JSP side and then it’s convenient for us to unpack it on the servlet side. •  Struts has taken this one step further. •  If you follow the rules,  Struts will automatically populate a JavaBean for you —saving you the trouble of loading it.   Struts:  ActionForm
[object Object],[object Object],[object Object],Struts:  ActionForm
[object Object],[object Object],[object Object],[object Object],Struts:  ActionForm
•  So, let’s recall our HTML/JSP file, and then see how we would create the correct ActionForm: Struts:  ActionForm <HTML> <HEAD><TITLE>Simple JSP</TITLE></HEAD> <BODY> <FORM METHOD=&quot;POST&quot; ACTION=&quot;/SomeServlet&quot;> <BR>Username: <INPUT TYPE=&quot;text&quot; NAME=&quot; user &quot; VALUE=&quot;&quot;> <BR>Password: <INPUT TYPE=&quot;text&quot; NAME=&quot; pass &quot; VALUE=&quot;&quot;> </FORM> </BODY> </HTML> import org.apache.struts.action.*; public class SimpleForm  extends ActionForm { private String  user  = “”; private String  pass  = “”; public SimpleForm(){} public void setUser( String u ) {  user  = u; } public void setPass( String p ) {  pass  = p; } public String getUser() { return  user ; } public String getPass() { return  pass ; } } As we see, our  SimpleForm  extends  ActionForm It has getters and setters named so they will be automatically found.
•  When compiled, this  .class  file should be placed here: webapps myapp WEB-INF classes   Struts:  ActionForm
Struts:  ActionForm •  Here’s what will happen. The  ActionServlet  will receive a POST, thereby executing its  doPost()  method. •  The  ActionServlet   will try to match the parameters  in the request with the properties in the  ActionForm . •  For a parameter  wxyz , the JavaBean ( ActionForm ) must have a corresponding  setWxyz()  and  getWxyz()  method.
Struts: ActionServlet
•  The  ActionServlet  behaves like an orchestra Conductor. It doesn’t do a lot of the work, but it manages the other components. •  The  ActionServlet  receives a request from the container and it routes the request to the correct place. •  99% of the time,  you will  never  need to change  the existing  ActionServlet   Struts:  ActionServlet
•  The  ActionServlet  uses a special xml configuration file called:  struts-config.xml . Struts:  ActionServlet When the web container receives a request in the form of  /register-complete/enter .do , then—because of the  .do  extension—it knows to pass the request off to the  ActionServlet . In turn, the  ActionServlet  looks in its  struts-config.xml  file to see where to send the request. Using this “mapping”, the  ActionServlet  knows to send the request to the JSP located at this path.  Thus, we have decoupled the location of the actual JSP from its location as implied by URL.
•  So, let’s review the sequence so far: 1.) Web container gets a request with a  .do  extension. 2.) Web container passes the request to the  ActionServlet 3.)  ActionServlet  grabs all the request parameters and tries to insert them in an  ActionForm . 4.)  ActionServlet  strips the  .do  extension. 5.)  ActionServlet  looks in the  struts-config.xml  file for a matching URI pattern. 6.) … Struts:  ActionServlet
Struts: ActionMapping
•  The Struts Java class called  ActionMapping  is used  inside of the  Action  class  (not yet covered). •  It has only one method we’re interested in: ActionMapping  mapping  = new ActionMapping(); mapping. findForward ( “somesymbolicname” ); •  This means: “When you reach this statement, you should forward the request to the JSP page represented by this symbolic name ‘ somesymbolicname ’.” Struts:  ActionMapping
Struts: Action
•  Recall that the business logic of a Struts application is all done in the  Action  class. •  You will often need to create your own subclass of this  Action  class. •  Your  Action  class must follow a very specific design pattern: Struts:  Action
import org.apache.struts.action.*; import javax.servlet.http.*; public class MyAction extends  Action { public ActionForward perform(   ActionMapping   mapping ,  ActionForm   form ,    HttpServletRequest req,   HttpServletResponse res  ) { } } After you have extended the  Action  class, you will need to override the inherited method called “ perform() ”. In order for your override to work, it must match the signature of the superclass, and thus it must take the form we see here.
import org.apache.struts.action.*; import javax.servlet.http.*; public class MyAction extends  Action { public ActionForward perform(   ActionMapping   mapping ,  ActionForm   form ,    HttpServletRequest req,   HttpServletResponse res  ) { SimpleForm   sf  = ( SimpleForm )  form ; String username =  sf .getUser(); String password =  sf .getPass(); } } Now, the first step is to  cast  the received  ActionForm  reference into your subclass of  ActionForm . In this case, it’s called  SimpleForm . Recall, since  SimpleForm  is an  ActionForm , we can perform this cast. import org.apache.struts.action.*; public class SimpleForm  extends ActionForm {
import org.apache.struts.action.*; import javax.servlet.http.*; public class MyAction extends  Action { public ActionForward perform(   ActionMapping   mapping ,  ActionForm   form ,    HttpServletRequest req,   HttpServletResponse res  ) { SimpleForm   sf  = ( SimpleForm )  form ; String username =  sf .getUser(); String password =  sf .getPass(); if( username == null || password == null ) {   return  mapping .findForward( “failure” ); } else {   return  mapping .findForward( “success” ); } } } Finally, we see how—depending on the results of the logic performed in this  Action  class—we use the  ActionMapping  class to decide where to send the request from here.
[object Object],[object Object],[object Object],[object Object],Struts:  Action
•  And let’s review how the  struts-config.xml  would be modified to use our action class: Struts:  Action Here we see a new attribute was added to the action. Within the Action class (our  MyAction ) we saw the “ findForward() ” method referred to the symbolic name “ success ”. Here’s where that is defined.
Struts: Review So Far
•  As you no doubt see, this can be confusing. •  The names chosen for the components are not that meaningful and the process is non-intuitive. •  Still, let’s see if we can understand the entire process. Struts:  Review So Far
1.) Point your browser to a web page. http://localhost:8080/ register-complete /enter.jsp Struts:  Review So Far First, we see that we’re executing the JSP called  enter.jsp  that lives in a web application called  register-complete .
2.) This is the HTML within the page  enter.jsp Struts:  Review So Far <form  name=&quot;registerForm&quot;  method=&quot;POST&quot; action=&quot;/ register-complete /enter .do &quot;> UserName: <input type=&quot;text&quot; name=&quot;username&quot; value=&quot;&quot;><br> enter password: <input type=&quot;password&quot; name=&quot;password1&quot; value=&quot;&quot;><br> re-enter password: <input type=&quot;password&quot; name=&quot;password2&quot; value=&quot;&quot;><br> <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Register&quot;> </form> When we click the Submit button, we trigger a POST against the page  /register-complete/enter.do . The web container sees that we have asked it to render a page that ends in  .do .  The web container knows that all page requests that end in  .do  should be sent to the  ActionServlet , which will be allowed to decide what to do.
3.) The  ActionServlet  receives the page request. It looks up the URI “mapping” pattern in its  struts-config.xml  file.   The  ActionServlet  also stores the request parameters in the  ActionForm  bean. Struts:  Review So Far Since we are already inside the  register-complete  web application, you can omit that part of the name. So, we’re doing a post against  /register-complete/enter.do . The  ActionServlet  knows to strip off the  .do , so it’s looking for a path mapped to  /enter . And, we see that does exist.
This is the  RegisterAction.java  class. Relying on the  struts-config.xml  file to identify this class, the  ActionServlet  will execute the  perform()  method.
[object Object],[object Object],[object Object],Struts:  Review So Far The  name  property tells it which  ActionForm  class to use.
5.) Since the  ActionServlet  has discovered an  ActionForm  is associated, it instantiates the bean and tries to call its getters and setters for each of the parameters in the request. Struts:  Review So Far This same line also informs the  ActionServlet  which  ActionForm  class it should use when it captures all the request parameter information.
6.) Finally, depending on the outcome of the business logic in the  RegisterAction  class, one of the  findForward()  methods is executed.  Struts:  Review So Far
Struts: Understanding the Architecture
Struts:  Understanding the Architecture •  Let’s first review the sequence of actions: 1.) A client requests a web page that matches the Action URI pattern. 2.) Seeing the  .do  extension, the web container passes the request to the  ActionServlet . 3.) The  ActionServlet  looks in its  struts-config.xml  for the mapping for that particular path. 4.) If that mapping specifies an  ActionForm  [JavaBean], the  ActionServlet  either uses an existing instance of that  ActionForm  or it instantiates a new one. The  ActionServlet  populates the  ActionForm . 5.) The  ActionServlet  sees which  Action  class is mapped to that path and executes the  perform()  method of that  Action  class. 6.) The  Action  class does what it needs for business logic. 7.) The  Action  returns an  ActionForward  to the  ActionServlet .
1, 2.) A client requests a web page that matches the Action URI pattern. Seeing the  .do  extension, the web container passes the request to the  ActionServlet .  How does this happen? Recall that the web container [the server] has its  web.xml  configuration file. Within that config file, there is an element called— <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern> *.do </url-pattern> </servlet-mapping> — that allows you to specify that all pages with this pattern should go to the servlet action.  Struts:  Understanding the Architecture
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Struts:  Understanding the Architecture
Struts: Our First Example
•  Once again, we will take the organic approach and see what happens in a linear fashion. •  Before then, I would like to explore the set up of the web app using Struts in the directory.  Struts:  Our First Example
This “ logon ” is the root of the web app. Every path will be considered relative to this directory. In  this  example, the  pages  directory will hold the JSP files. You have some flexibility in where you place your JSPs, but wherever they go, you must make sure your paths reflect that location. This  WEB-INF  directory is very important. In it we will find the files at right.  We will explore these files more on the next slide. Our  Action  classes must go in this directory. In this case, we see an  app  directory—which tells us that our  Action  class specified that it was in a package called  app . The resources directory will hold  .properties  files, such as  Messages.properties  or any other resource we might need. Finally, the  lib  directory holds JAR files such as the  struts.jar  file.
•  As you recall from the previous slide, these files are contained in the  WEB-INF  directory.  Struts:  Our First Example The  web.xml  file is the same one that must be present in all web applications. In our case, aside from listing the  ActionServlet  as being present, this  web.xml  has a line that informs it to send all pages with a  .do  extension to the  ActionServlet  for processing. web.xml
•  This slide explores the  struts-config.xml  file Struts:  Our First Example First, we create a key “logonForm” that gives the name of our  ActionForm struts-config.xml These  <action-mappings>  tell the  ActionServlet  which  Action  class to execute when it encounters a particular URI pattern. In this example, you see that a  forward  has been declared. This must work in concert with the business logic in the  Action  class.
•  This is a look at the HTML behind our first JSP.  Struts:  Our First Example Welcome.jsp

Más contenido relacionado

La actualidad más candente

Creational pattern
Creational patternCreational pattern
Creational patternHimanshu
 
What Is Express JS?
What Is Express JS?What Is Express JS?
What Is Express JS?Simplilearn
 
Introduction to WordPress Development - Hooks
Introduction to WordPress Development - HooksIntroduction to WordPress Development - Hooks
Introduction to WordPress Development - HooksEdmund Chan
 
Angular state Management-NgRx
Angular state Management-NgRxAngular state Management-NgRx
Angular state Management-NgRxKnoldus Inc.
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State managementShivanand Arur
 
UDA-Plugin UDA. Guia de desarrollo
UDA-Plugin UDA. Guia de desarrolloUDA-Plugin UDA. Guia de desarrollo
UDA-Plugin UDA. Guia de desarrolloAnder Martinez
 
Production Experience: Some Insights from Using Vercel and Next.js for Over 3...
Production Experience: Some Insights from Using Vercel and Next.js for Over 3...Production Experience: Some Insights from Using Vercel and Next.js for Over 3...
Production Experience: Some Insights from Using Vercel and Next.js for Over 3...KosukeMatano1
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSCarol McDonald
 
UDA-Guia de desarrollo
UDA-Guia de desarrolloUDA-Guia de desarrollo
UDA-Guia de desarrolloAnder Martinez
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event HandlingWebStackAcademy
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2sandeep54552
 

La actualidad más candente (20)

Angular
AngularAngular
Angular
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Chapter 7 Use Case Model
Chapter 7 Use Case ModelChapter 7 Use Case Model
Chapter 7 Use Case Model
 
What Is Express JS?
What Is Express JS?What Is Express JS?
What Is Express JS?
 
Introduction to WordPress Development - Hooks
Introduction to WordPress Development - HooksIntroduction to WordPress Development - Hooks
Introduction to WordPress Development - Hooks
 
Angular state Management-NgRx
Angular state Management-NgRxAngular state Management-NgRx
Angular state Management-NgRx
 
Jsp presentation
Jsp presentationJsp presentation
Jsp presentation
 
THREADS EM JAVA: INTRODUÇÃO
THREADS EM JAVA: INTRODUÇÃOTHREADS EM JAVA: INTRODUÇÃO
THREADS EM JAVA: INTRODUÇÃO
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State management
 
UDA-Plugin UDA. Guia de desarrollo
UDA-Plugin UDA. Guia de desarrolloUDA-Plugin UDA. Guia de desarrollo
UDA-Plugin UDA. Guia de desarrollo
 
Production Experience: Some Insights from Using Vercel and Next.js for Over 3...
Production Experience: Some Insights from Using Vercel and Next.js for Over 3...Production Experience: Some Insights from Using Vercel and Next.js for Over 3...
Production Experience: Some Insights from Using Vercel and Next.js for Over 3...
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
 
UDA-Guia de desarrollo
UDA-Guia de desarrolloUDA-Guia de desarrollo
UDA-Guia de desarrollo
 
Get to Know AtoM's Codebase
Get to Know AtoM's CodebaseGet to Know AtoM's Codebase
Get to Know AtoM's Codebase
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2
 
Git basic
Git basicGit basic
Git basic
 
Jsp tag library
Jsp tag libraryJsp tag library
Jsp tag library
 
Salesforce asynchronous apex
Salesforce asynchronous apexSalesforce asynchronous apex
Salesforce asynchronous apex
 
Use case diagrams
Use case diagramsUse case diagrams
Use case diagrams
 

Destacado

Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Strutsyesprakash
 
Apache Velocity
Apache Velocity Apache Velocity
Apache Velocity yesprakash
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts weili_at_slideshare
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 

Destacado (6)

Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Struts
 
Apache Velocity
Apache Velocity Apache Velocity
Apache Velocity
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts
 
Struts
StrutsStruts
Struts
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 

Similar a Struts Java I I Lecture 8

Struts tutorial
Struts tutorialStruts tutorial
Struts tutorialOPENLANE
 
Introduction to Struts
Introduction to StrutsIntroduction to Struts
Introduction to Strutselliando dias
 
Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...varunsunny21
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applicationselliando dias
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohanWebVineet
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppSyed Shahul
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet Sagar Nakul
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet Sagar Nakul
 
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Arun Gupta
 

Similar a Struts Java I I Lecture 8 (20)

Struts tutorial
Struts tutorialStruts tutorial
Struts tutorial
 
Struts Intro
Struts IntroStruts Intro
Struts Intro
 
Introduction to Struts
Introduction to StrutsIntroduction to Struts
Introduction to Struts
 
Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applications
 
Ajax
AjaxAjax
Ajax
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Ajax
AjaxAjax
Ajax
 
Json generation
Json generationJson generation
Json generation
 
Struts Action
Struts ActionStruts Action
Struts Action
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts App
 
Struts,Jsp,Servlet
Struts,Jsp,ServletStruts,Jsp,Servlet
Struts,Jsp,Servlet
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
 
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
 
14 mvc
14 mvc14 mvc
14 mvc
 
Struts2 - 101
Struts2 - 101Struts2 - 101
Struts2 - 101
 
Struts framework
Struts frameworkStruts framework
Struts framework
 

Más de patinijava

Más 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
 
Struts N E W
Struts N E WStruts N E W
Struts N E W
 
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
 
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

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
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
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Último (20)

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
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.
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

Struts Java I I Lecture 8

  • 4. • Once you’ve coded a lot of JSP applications, you find yourself doing a lot of repetitive things. • Also, if you have a hard-coded link scattered around a lot of JSPs, the first time you need to change that link you discover a special kind of agony. • Struts was designed to solve that problem and a few others. • Struts is about moving code to xml property files. Struts: Introduction * * This lecture was based on “ Struts in Action ” by Ted Husted ISBN 1-930110-50-2
  • 5. • Struts is based on the MVC or Model-View-Controller design pattern. Struts: Introduction
  • 6. • Under Struts the work of operating a web application is divided up: ActionServlet —this Struts component controls navigation. Action —this Struts component controls business logic. Struts: Introduction
  • 7. • Here’s the process: 1.) An ActionServlet receives a request from the container. 2.) The ActionServlet collects the information in the request. 3.) Using the request URI, the ActionServlet tries to match the URI with a so-called Action class. 4.) Whichever Action class is passed the request will take the correct course of action. Struts: Introduction
  • 8. • The preceding is just a general idea of how it works. • Struts uses the following Java classes to work its magic: ActionForm ActionServlet ActionMapping ActionForward Action • In addition to these, Struts places a lot of information in xml configuration files: strut-config.xml Struts: Introduction
  • 9. We will explore these in depth, but here’s a thumbnail version of each: ActionForm —Collects form data from HTML page. ActionServlet —Controls everything. ActionMapping —Helps when deciding where to go. ActionForward —Where to send request Action —Called to do business logic. Struts: Introduction
  • 11. • A Web Application is driven by HTML pages. • A typical WebApp contains text fields in a FORM . • To extract information from this page, we use the NAME . Struts: ActionForm <HTML> <HEAD><TITLE>Simple JSP</TITLE></HEAD> <BODY> <FORM METHOD=&quot;POST&quot; ACTION=&quot;/TestServlet&quot;> <BR>Username: <INPUT TYPE=&quot;text&quot; NAME =&quot; user &quot; VALUE=&quot;&quot;> <BR>Password: <INPUT TYPE=&quot;text&quot; NAME =&quot; pass &quot; VALUE=&quot;&quot;> </FORM> </BODY> </HTML>
  • 12. • Given the HTML page we see below, we could pull out the value of the tag with the NAME of user by using the following code in a Servlet’s doPost() method: String userField = request.getParameter(&quot; user &quot;); Struts: ActionForm <HTML> <HEAD><TITLE>Simple JSP</TITLE></HEAD> <BODY> <FORM METHOD=&quot;POST&quot; ACTION=&quot;/SomeServlet&quot;> <BR>Username: <INPUT TYPE=&quot;text&quot; NAME =&quot; user &quot; VALUE=&quot;&quot;> <BR>Password: <INPUT TYPE=&quot;text&quot; NAME =&quot; pass &quot; VALUE=&quot;&quot;> </FORM> </BODY> </HTML>
  • 13. • However, with any fairly large page, this becomes tedious. • A better way is to use a JavaBean . • Using a JavaBean , we place all the data in the bean on the JSP side and then it’s convenient for us to unpack it on the servlet side. • Struts has taken this one step further. • If you follow the rules, Struts will automatically populate a JavaBean for you —saving you the trouble of loading it. Struts: ActionForm
  • 14.
  • 15.
  • 16. • So, let’s recall our HTML/JSP file, and then see how we would create the correct ActionForm: Struts: ActionForm <HTML> <HEAD><TITLE>Simple JSP</TITLE></HEAD> <BODY> <FORM METHOD=&quot;POST&quot; ACTION=&quot;/SomeServlet&quot;> <BR>Username: <INPUT TYPE=&quot;text&quot; NAME=&quot; user &quot; VALUE=&quot;&quot;> <BR>Password: <INPUT TYPE=&quot;text&quot; NAME=&quot; pass &quot; VALUE=&quot;&quot;> </FORM> </BODY> </HTML> import org.apache.struts.action.*; public class SimpleForm extends ActionForm { private String user = “”; private String pass = “”; public SimpleForm(){} public void setUser( String u ) { user = u; } public void setPass( String p ) { pass = p; } public String getUser() { return user ; } public String getPass() { return pass ; } } As we see, our SimpleForm extends ActionForm It has getters and setters named so they will be automatically found.
  • 17. • When compiled, this .class file should be placed here: webapps myapp WEB-INF classes Struts: ActionForm
  • 18. Struts: ActionForm • Here’s what will happen. The ActionServlet will receive a POST, thereby executing its doPost() method. • The ActionServlet will try to match the parameters in the request with the properties in the ActionForm . • For a parameter wxyz , the JavaBean ( ActionForm ) must have a corresponding setWxyz() and getWxyz() method.
  • 20. • The ActionServlet behaves like an orchestra Conductor. It doesn’t do a lot of the work, but it manages the other components. • The ActionServlet receives a request from the container and it routes the request to the correct place. • 99% of the time, you will never need to change the existing ActionServlet Struts: ActionServlet
  • 21. • The ActionServlet uses a special xml configuration file called: struts-config.xml . Struts: ActionServlet When the web container receives a request in the form of /register-complete/enter .do , then—because of the .do extension—it knows to pass the request off to the ActionServlet . In turn, the ActionServlet looks in its struts-config.xml file to see where to send the request. Using this “mapping”, the ActionServlet knows to send the request to the JSP located at this path. Thus, we have decoupled the location of the actual JSP from its location as implied by URL.
  • 22. • So, let’s review the sequence so far: 1.) Web container gets a request with a .do extension. 2.) Web container passes the request to the ActionServlet 3.) ActionServlet grabs all the request parameters and tries to insert them in an ActionForm . 4.) ActionServlet strips the .do extension. 5.) ActionServlet looks in the struts-config.xml file for a matching URI pattern. 6.) … Struts: ActionServlet
  • 24. • The Struts Java class called ActionMapping is used inside of the Action class (not yet covered). • It has only one method we’re interested in: ActionMapping mapping = new ActionMapping(); mapping. findForward ( “somesymbolicname” ); • This means: “When you reach this statement, you should forward the request to the JSP page represented by this symbolic name ‘ somesymbolicname ’.” Struts: ActionMapping
  • 26. • Recall that the business logic of a Struts application is all done in the Action class. • You will often need to create your own subclass of this Action class. • Your Action class must follow a very specific design pattern: Struts: Action
  • 27. import org.apache.struts.action.*; import javax.servlet.http.*; public class MyAction extends Action { public ActionForward perform( ActionMapping mapping , ActionForm form , HttpServletRequest req, HttpServletResponse res ) { } } After you have extended the Action class, you will need to override the inherited method called “ perform() ”. In order for your override to work, it must match the signature of the superclass, and thus it must take the form we see here.
  • 28. import org.apache.struts.action.*; import javax.servlet.http.*; public class MyAction extends Action { public ActionForward perform( ActionMapping mapping , ActionForm form , HttpServletRequest req, HttpServletResponse res ) { SimpleForm sf = ( SimpleForm ) form ; String username = sf .getUser(); String password = sf .getPass(); } } Now, the first step is to cast the received ActionForm reference into your subclass of ActionForm . In this case, it’s called SimpleForm . Recall, since SimpleForm is an ActionForm , we can perform this cast. import org.apache.struts.action.*; public class SimpleForm extends ActionForm {
  • 29. import org.apache.struts.action.*; import javax.servlet.http.*; public class MyAction extends Action { public ActionForward perform( ActionMapping mapping , ActionForm form , HttpServletRequest req, HttpServletResponse res ) { SimpleForm sf = ( SimpleForm ) form ; String username = sf .getUser(); String password = sf .getPass(); if( username == null || password == null ) { return mapping .findForward( “failure” ); } else { return mapping .findForward( “success” ); } } } Finally, we see how—depending on the results of the logic performed in this Action class—we use the ActionMapping class to decide where to send the request from here.
  • 30.
  • 31. • And let’s review how the struts-config.xml would be modified to use our action class: Struts: Action Here we see a new attribute was added to the action. Within the Action class (our MyAction ) we saw the “ findForward() ” method referred to the symbolic name “ success ”. Here’s where that is defined.
  • 33. • As you no doubt see, this can be confusing. • The names chosen for the components are not that meaningful and the process is non-intuitive. • Still, let’s see if we can understand the entire process. Struts: Review So Far
  • 34. 1.) Point your browser to a web page. http://localhost:8080/ register-complete /enter.jsp Struts: Review So Far First, we see that we’re executing the JSP called enter.jsp that lives in a web application called register-complete .
  • 35. 2.) This is the HTML within the page enter.jsp Struts: Review So Far <form name=&quot;registerForm&quot; method=&quot;POST&quot; action=&quot;/ register-complete /enter .do &quot;> UserName: <input type=&quot;text&quot; name=&quot;username&quot; value=&quot;&quot;><br> enter password: <input type=&quot;password&quot; name=&quot;password1&quot; value=&quot;&quot;><br> re-enter password: <input type=&quot;password&quot; name=&quot;password2&quot; value=&quot;&quot;><br> <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Register&quot;> </form> When we click the Submit button, we trigger a POST against the page /register-complete/enter.do . The web container sees that we have asked it to render a page that ends in .do . The web container knows that all page requests that end in .do should be sent to the ActionServlet , which will be allowed to decide what to do.
  • 36. 3.) The ActionServlet receives the page request. It looks up the URI “mapping” pattern in its struts-config.xml file.  The ActionServlet also stores the request parameters in the ActionForm bean. Struts: Review So Far Since we are already inside the register-complete web application, you can omit that part of the name. So, we’re doing a post against /register-complete/enter.do . The ActionServlet knows to strip off the .do , so it’s looking for a path mapped to /enter . And, we see that does exist.
  • 37. This is the RegisterAction.java class. Relying on the struts-config.xml file to identify this class, the ActionServlet will execute the perform() method.
  • 38.
  • 39. 5.) Since the ActionServlet has discovered an ActionForm is associated, it instantiates the bean and tries to call its getters and setters for each of the parameters in the request. Struts: Review So Far This same line also informs the ActionServlet which ActionForm class it should use when it captures all the request parameter information.
  • 40. 6.) Finally, depending on the outcome of the business logic in the RegisterAction class, one of the findForward() methods is executed. Struts: Review So Far
  • 42. Struts: Understanding the Architecture • Let’s first review the sequence of actions: 1.) A client requests a web page that matches the Action URI pattern. 2.) Seeing the .do extension, the web container passes the request to the ActionServlet . 3.) The ActionServlet looks in its struts-config.xml for the mapping for that particular path. 4.) If that mapping specifies an ActionForm [JavaBean], the ActionServlet either uses an existing instance of that ActionForm or it instantiates a new one. The ActionServlet populates the ActionForm . 5.) The ActionServlet sees which Action class is mapped to that path and executes the perform() method of that Action class. 6.) The Action class does what it needs for business logic. 7.) The Action returns an ActionForward to the ActionServlet .
  • 43. 1, 2.) A client requests a web page that matches the Action URI pattern. Seeing the .do extension, the web container passes the request to the ActionServlet .  How does this happen? Recall that the web container [the server] has its web.xml configuration file. Within that config file, there is an element called— <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern> *.do </url-pattern> </servlet-mapping> — that allows you to specify that all pages with this pattern should go to the servlet action. Struts: Understanding the Architecture
  • 44.
  • 45. Struts: Our First Example
  • 46. • Once again, we will take the organic approach and see what happens in a linear fashion. • Before then, I would like to explore the set up of the web app using Struts in the directory. Struts: Our First Example
  • 47. This “ logon ” is the root of the web app. Every path will be considered relative to this directory. In this example, the pages directory will hold the JSP files. You have some flexibility in where you place your JSPs, but wherever they go, you must make sure your paths reflect that location. This WEB-INF directory is very important. In it we will find the files at right. We will explore these files more on the next slide. Our Action classes must go in this directory. In this case, we see an app directory—which tells us that our Action class specified that it was in a package called app . The resources directory will hold .properties files, such as Messages.properties or any other resource we might need. Finally, the lib directory holds JAR files such as the struts.jar file.
  • 48. • As you recall from the previous slide, these files are contained in the WEB-INF directory. Struts: Our First Example The web.xml file is the same one that must be present in all web applications. In our case, aside from listing the ActionServlet as being present, this web.xml has a line that informs it to send all pages with a .do extension to the ActionServlet for processing. web.xml
  • 49. • This slide explores the struts-config.xml file Struts: Our First Example First, we create a key “logonForm” that gives the name of our ActionForm struts-config.xml These <action-mappings> tell the ActionServlet which Action class to execute when it encounters a particular URI pattern. In this example, you see that a forward has been declared. This must work in concert with the business logic in the Action class.
  • 50. • This is a look at the HTML behind our first JSP. Struts: Our First Example Welcome.jsp