Struts Intro Course
Struts Intro Course
Introduction to Struts
Course Overview
Unit 1 - Model-View-Controller Design
Pattern
Unit 2 - Model Components
Unit 3 - View Components
Unit 4 - Controller Components
Unit 5 - Tag Libraries
Unit 1
Unit 2
Enterprise JavaBeans
ActionForm Beans
Extends the ActionForm class
Create one for each input form in the application
If defined in the ActionMapping configuration file,
the Controller Servlet will perform the following:
Check session for instance of bean of appropriate class
If no session bean exists, one is created automatically
For every request parameter whose name corresponds
to the name of a property in the bean, the corresponding
setter method will be called
The updated ActionForm bean will be passed to the
Action Class perform() method when it is called,
making these values immediately available
Continued
Define a property (with associated getXxx() and
setXxx() methods) for each field that is present in
the form. The field name and property name must
match according to the usual JavaBeans
conventions
Place a bean instance on your form, and use
nested property references. For example, you
have a "customer" bean on your Action Form, and
then refer to the property "customer.name" in your
JSP view. This would correspond to the methods
customer.getName() and
customer.setName(string Name) on your
customer bean
Project Refinery, Inc. 14
STRUTS Model Components
Unit 3
Internationalized Messages
Struts builds upon Java platform to provide assistance
for building internationalized and localized
applications
Locale - fundamental Java class that supports
internationalization
ResourceBundle - supports messages in multiple languages
PropertyResourceBundle - standard implementation of
ResourceBundle that allows you to define resources using
the same "name=value" syntax used to initialize properties
files
MessageFormat - allows you to replace portions of a
message string with arguments specified at run time
MessageResources - lets you treat a set of resource bundles
like a database, and allows you to request a particular
message string forProject
a particular Locale
Refinery, Inc. 20
STRUTS View Components
ApplicationResources.properties
Contains the messages in the default
language for your server. If your default
language is English, you might have an
entry like this: prompt.hello=Hello
ApplicationResources_xx.properties
Contains
the same messages in the
language whose ISO language code is "xx"
Unit 4
Action Classes:
The Action class defines a perform
method that you override
public ActionForward
perform(ActionMapping mapping,
ActionForm form, HttpServletRequest
request, HttpServletResponse response)
throws IOException, ServletException;
<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 or session level
attribute that this form bean will be stored as
type: The fully-qualified Java classname of your form
bean
<action-mappings>
This section contains your action definitions. You
use an <action> element for each of your actions
you would like to define. Each action element has
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 <form-bean> element to use
with this action
The
Web Application Deployment
Descriptor
The final step in setting up the application
is to configure the application deployment
descriptor (stored in file WEB-
INF/web.xml) to include all the Struts
components that are required
Unit 5
HTML Tags
Bean Tags
Logic Tags
Template Tags
Custom Tags
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.
parameter Define a scripting variable based on the value(s) of the specified request parameter.
write Render the value of the specified bean property to the current JspWriter.
Unit 6
Unit 7
<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>
Project Refinery, Inc. 73
Application Resources File
Unit 8
Unit 9