Understanding Controller Components and Action Mapping in Struts Framework, Slides of Java Programming

An overview of the role of various controller components, including actionservlet, requestprocessor, and action, in the struts framework. It also explains the concept of actionmapping and its configuration in the struts-config.xml file. Developers can use this information to build web applications using the struts framework.

Typology: Slides

2011/2012

Uploaded on 08/09/2012

dhanyaa
dhanyaa 🇮🇳

4.7

(3)

60 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Developer Responsibility
Write an Action class (that is, an extension of the
Action class) for each logical request that may be
received
override execute() method (perform() method in Struts 1.0)
Write the action mapping configuration file
struts-config.xml
Update the web application deployment descriptor
file to specify the ActionServlet
web.xml
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Understanding Controller Components and Action Mapping in Struts Framework and more Slides Java Programming in PDF only on Docsity!

Developer Responsibility

 Write an Action class (that is, an extension of the

Action class) for each logical request that may be

received

 override execute() method (perform() method in Struts 1.0)

 Write the action mapping configuration file

 struts-config.xml

 Update the web application deployment descriptor

file to specify the ActionServlet

 web.xml

Controller Components in Struts

Framework

 ActionServlet (Provided by Struts)

 RequestProcessor (Struts 1.1)(Provided by Struts)

 One for each module

 Action (Provided by developer)

 Developer extends Struts-provided Action class

 Action Mapping (Specified by developer)

 Developer specifies action mapping in struts- config.xml file  Struts framework creates ActionMapping object and passes it to Action object

What Does ActionServlet Do?

 Performs the role of Controller

 Process user requests  Determine what the user is trying to achieve according to the request  Pull data from the model (if necessary) to be given to the appropriate view, and  Select the proper view to respond to the user

 Delegates most of this grunt work to Action classes

What Does ActionServlet Do?

(Continued)

 Is responsible for initialization and clean-up of

resources

 loads the application config corresponding to the "config" init-param's in web.xml  goes through an enumeration of all init-param elements, looking for those elements who's name starts with config/ for modules  To access the module foo, you would use a URL like:  http://localhost: 8080 /myApp/foo/someAction.do

RequestProcessor

(Provided by

Framework)

What Does RequestProcessor Do?

 processPath

 Determine the path that invoked us. This will be used later to retrieve an ActionMapping.

 processLocale

 Select a locale for this request, if one hasn't already been selected, and place it in the request.

 processContent

 Set the default content type (with optional character encoding) for all responses if requested.

What Does RequestProcessor Do?

 processMapping

 Determine the ActionMapping associated with this path.

 processRoles

 If the mapping has a role associated with it, ensure the requesting user is has the specified role. If they do not, raise an error and stop processing of the request.

 processActionForm

 Instantiate (if necessary) the ActionForm associated with this mapping (if any) and place it into the appropriate scope.

What Does RequestProcessor Do?

 processPopulate

 Populate the ActionForm associated with this request, if any.

 processValidate

 Perform validation (if requested) on the ActionForm associated with this request (if any).

 processForward

 If this mapping represents a forward, forward to the path specified by the mapping.

What Does RequestProcessor Do?

 processForwardConfig

 Finally, the process method of the RequestProcessor takes the ActionForward returned by your Action class, and uses to select the next resource (if any). Most often the ActionForward leads to the presentation page that renders the response.

Action Mapping

(You provide it)

Struts Config File

(struts-config.xml)

 struts-config.xml contains three important elements

used to describe actions:

 <form-beans> contains FormBean definitions including name and type (classname)  <action-mapping> contains action definitions  Use an element for each action defined  <global-forwards> contains your global forward definitions

Struts Config File

(struts-config.xml)

 <form-beans>

 This section contains your form bean definitions.  You use a <form-bean> element for each form bean, which has the following important attributes:  name: The name of the request (and session level attribute that this form bean will be stored as)  type: The fully-qualified Java classname of your form bean

Struts Config File

(struts-config.xml)

 <action-mappings>

 This section contains your action definitions. You use an element for each of your actions you would like to define.

Struts Config File

(struts-config.xml)

 <action-mappings>

 Each element requires the following attributes to be defined:  path: The application context-relative path to the action (URI of the request)  type: The fully qualified java classname of your Action class  name: The name of your <form-bean> element to use with this action  input: The name of the display page when input form validation error condition occurs  scope: The scope in which form bean is created  validate: Whether to perform input form validation or not