Upload
kamalakar-dandu
View
222
Download
0
Embed Size (px)
Citation preview
8/2/2019 Struts Intro Course by Kamalakar Dandu
1/77
Project Refinery, Inc. 1
STRUTSPart of the Jakarta Project
Sponsored by theApache Software Foundation
Developed by: Roger W Barnes of Project Refinery, Inc.
Introduction to Struts
8/2/2019 Struts Intro Course by Kamalakar Dandu
2/77
Project Refinery, Inc. 2
STRUTS Objectives
Course Overview
Unit 1 - Model-View-Controller Design
PatternUnit 2 - Model Components
Unit 3 - View Components
Unit 4 - Controller ComponentsUnit 5 - Tag Libraries
8/2/2019 Struts Intro Course by Kamalakar Dandu
3/77
Project Refinery, Inc. 3
STRUTS Objectives
Unit 6 - STRUTS Configuration File
Unit 7 - Web Application Descriptor File
Unit 8 - Application Resources FileUnit 9 Resources
8/2/2019 Struts Intro Course by Kamalakar Dandu
4/77
Project Refinery, Inc. 4
Model-View-Controller DesignPattern
Unit 1
8/2/2019 Struts Intro Course by Kamalakar Dandu
5/77
Project Refinery, Inc. 5
STRUTS MVC Design Pattern
Central controller mediates applicationflow
Controller delegates to appropriatehandler
Handlers are tied to model components
Model encapsulates business logicControl forwarded back through the
Controller to the appropriate View
8/2/2019 Struts Intro Course by Kamalakar Dandu
6/77
Project Refinery, Inc. 6
STRUTS MVC Design Pattern
8/2/2019 Struts Intro Course by Kamalakar Dandu
7/77Project Refinery, Inc. 7
STRUTS MVC Design Pattern
3 Major Components in STRUTS
Servlet controller (Controller)
Java Server Pages (View)Application Business Logic (Model)
Controller bundles and routes HTTPrequest to other objects in framework
Controller parses configuration file
8/2/2019 Struts Intro Course by Kamalakar Dandu
8/77Project Refinery, Inc. 8
STRUTS MVC Design Pattern
Configuration file contains actionmappings (determines navigation)
Controller uses mappings to turn HTTPrequests into application actions
Mapping must specify
A request pathObject type to act upon the request
8/2/2019 Struts Intro Course by Kamalakar Dandu
9/77
Project Refinery, Inc. 9
Model Components
Unit 2
8/2/2019 Struts Intro Course by Kamalakar Dandu
10/77Project Refinery, Inc. 10
STRUTS Model Components
Model divided into concepts
Internal state of the system
Actions that can change that state Internal state of system represented by
JavaBeans
Enterprise JavaBeans
8/2/2019 Struts Intro Course by Kamalakar Dandu
11/77Project Refinery, Inc. 11
STRUTS Model Components
JavaBeans and Scope Page visible within a single JSP page, for the
lifetime of the current request
Request visible within a single JSP page, as wellas to any page or servlet that is included in thispage, or forwarded to by this page
Session visible to all JSP pages and servletsthat participate in a particular user session, across
one or more requests Application - visible to all JSP pages and servlets
that are part of a web application
8/2/2019 Struts Intro Course by Kamalakar Dandu
12/77Project Refinery, Inc. 12
STRUTS Model Components
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 correspondingsetter method will be called
The updatedActionForm bean will be passed to theAction Class perform() method when it is called, makingthese values immediately available
8/2/2019 Struts Intro Course by Kamalakar Dandu
13/77
Project Refinery, Inc. 13
STRUTS Model Components
When coding ActionForm beans consider: The ActionForm class itself requires no specific
methods to be implemented. It is used to identifythe role these particular beans play in the overallarchitecture. Typically, an ActionForm bean willhave only property getter and property settermethods, with no business logic
The ActionForm object also offers a standard
validation mechanism. If you override a "stub"method, and provide error messages in thestandard application resource, Struts willautomatically validate the input from the form
8/2/2019 Struts Intro Course by Kamalakar Dandu
14/77
Project Refinery, Inc. 14
STRUTS Model Components
Continued Define a property (with associated getXxx() and
setXxx() methods) for each field that is present inthe form. The field name and property name mustmatch according to the usual JavaBeansconventions
Place a bean instance on your form, and usenested property references. For example, you
have a "customer" bean on your Action Form, andthen refer to the property "customer.name" in yourJSP view. This would correspond to the methodscustomer.getName() andcustomer.setName(string Name) on your
customer bean
8/2/2019 Struts Intro Course by Kamalakar Dandu
15/77
Project Refinery, Inc. 15
STRUTS Model Components
System State Beans
Actual state of a system is normally representedas a set of one or more JavaBeans classes,
whose properties define the current state A shopping cart system, for example, will include a
bean that represents the cart being maintained foreach individual shopper, and will (among other
things) include the set of items that the shopperhas currently selected for purchase
8/2/2019 Struts Intro Course by Kamalakar Dandu
16/77
Project Refinery, Inc. 16
STRUTS Model Components
Business Logic Beans Should encapsulate the functional logic of your
application as method calls on JavaBeansdesigned for this purpose
For maximum code re-use, business logic beansshould be designed and implemented so that theydo not know they are being executed in a webapplication environment
For small to medium sized applications, businesslogic beans might be ordinary JavaBeans thatinteract with system state beans passed asarguments, or ordinary JavaBeans that access adatabase using JDBC calls
8/2/2019 Struts Intro Course by Kamalakar Dandu
17/77
Project Refinery, Inc. 17
STRUTS Model Components
Business Logic Beans - Continued
For larger applications, these beans willoften be stateful or stateless Enterprise
JavaBeans (EJBs)
8/2/2019 Struts Intro Course by Kamalakar Dandu
18/77
Project Refinery, Inc. 18
STRUTS Model Components
Accessing Relational Databases
Struts can define the datasources for anapplication from within its standard
configuration file
A simple JDBC connection pool is alsoprovided
8/2/2019 Struts Intro Course by Kamalakar Dandu
19/77
Project Refinery, Inc. 19
View Components
Unit 3
8/2/2019 Struts Intro Course by Kamalakar Dandu
20/77
Project Refinery, Inc. 20
STRUTS View Components
Internationalized Messages Struts builds upon Java platform to provide
assistance for building internationalized and localizedapplications Locale - fundamental Java class that supports
internationalization
ResourceBundle - supports messages in multiple languages
PropertyResourceBundle - standard implementation ofResourceBundle that allows you to define resources using
the same "name=value" syntax used to initialize propertiesfiles
MessageFormat - allows you to replace portions of amessage 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 particularmessage string for a particular Locale
8/2/2019 Struts Intro Course by Kamalakar Dandu
21/77
Project Refinery, Inc. 21
STRUTS View Components
ApplicationResources.properties
Contains the messages in the defaultlanguage for your server. If your default
language is English, you might have anentry like this: prompt.hello=Hello
ApplicationResources_xx.properties
Contains the same messages in thelanguage whose ISO language code is "xx"
8/2/2019 Struts Intro Course by Kamalakar Dandu
22/77
Project Refinery, Inc. 22
STRUTS View Components
Forms and FormBean interactions
HTML Forms and their limitations
Errors not easily handled
8/2/2019 Struts Intro Course by Kamalakar Dandu
23/77
Project Refinery, Inc. 23
STRUTS View Components
8/2/2019 Struts Intro Course by Kamalakar Dandu
24/77
Project Refinery, Inc. 24
STRUTS View Components
Building Forms with Struts
The taglib directive tells the JSP page compiler
where to find the tag library descriptorfor the
Struts tag library message tag is used to look up internationalized
message strings from a MessageResources
object containing all the resources for thisapplication
The errors tag displays any error messages thathave been stored by a business logic component,or nothing if no errors have been stored
8/2/2019 Struts Intro Course by Kamalakar Dandu
25/77
Project Refinery, Inc. 25
STRUTS View Components
Building Forms with Struts continued The form tag renders an HTML element,
based on the specified attributes
The form tag also associates all of the fields withinthis form with a request scoped FormBean that isstored under the key FormName
The form bean can also be specified in the Strutsconfiguration file, in which case the Name and
Type can be omitted here The text tag renders an HTML element of
type "text
The submit and reset tags generate thecorresponding buttons at the bottom of the form
8/2/2019 Struts Intro Course by Kamalakar Dandu
26/77
Project Refinery, Inc. 26
STRUTS View Components
Input field types supported checkboxes
hidden fields
password input fields radio buttons
reset buttons
select lists
options submit buttons
text input fields
textareas
8/2/2019 Struts Intro Course by Kamalakar Dandu
27/77
Project Refinery, Inc. 27
STRUTS View Components
Useful Presentation Tags [logic] iterate repeats its tag body once for each
element of a specified collection (which can be anEnumeration, a Hashtable, a Vector, or an array of
objects) [logic] present depending on which attribute is
specified, this tag checks the current request, andevaluates the nested body content of this tag only
if the specified value is present [logic] notPresent the companion tag to present,
notPresent provides the same functionality whenthe specified attribute is not present
http://../Java%20Docs/STRUTS/Docs/struts-logic.htmlhttp://../Java%20Docs/STRUTS/Docs/struts-logic.htmlhttp://../Java%20Docs/STRUTS/Docs/struts-logic.htmlhttp://../Java%20Docs/STRUTS/Docs/struts-logic.htmlhttp://../Java%20Docs/STRUTS/Docs/struts-logic.htmlhttp://../Java%20Docs/STRUTS/Docs/struts-logic.html8/2/2019 Struts Intro Course by Kamalakar Dandu
28/77
Project Refinery, Inc. 28
STRUTS View Components
Useful Presentation Tags continued [html] link generates a HTML element as an
anchor definition or a hyperlink to the specifiedURL, and automatically applies URL encoding to
maintain session state in the absence of cookiesupport
[html] img generates a HTML element withthe ability to dynamically modify the URLs
specified by the "src" and "lowsrc" attributes in thesame manner that can
[bean] parameter retrieves the value of thespecified request parameter, and defines theresult as a page scope attribute of type String or
String
http://../Java%20Docs/STRUTS/Docs/struts-html.htmlhttp://../Java%20Docs/STRUTS/Docs/struts-html.htmlhttp://../Java%20Docs/STRUTS/Docs/struts-bean.htmlhttp://../Java%20Docs/STRUTS/Docs/struts-bean.htmlhttp://../Java%20Docs/STRUTS/Docs/struts-html.htmlhttp://../Java%20Docs/STRUTS/Docs/struts-html.html8/2/2019 Struts Intro Course by Kamalakar Dandu
29/77
Project Refinery, Inc. 29
STRUTS View Components
Automatic Form Validation
Struts offers an additional facility to validate theinput fields it has received
To utilize this feature, override the validate()method in your ActionForm class
The validate() method is called by the controllerservlet after the bean properties have been
populated, but before the corresponding actionclass's perform() method is invoked
8/2/2019 Struts Intro Course by Kamalakar Dandu
30/77
Project Refinery, Inc. 30
STRUTS View Components
Page Composition with Includes The development of the various segments
of a site is easier if you can divide up the
work, and assign different developers tothe different segments
Use the includecapability of JavaServerPages technology to combine the results
into a single result page, or use the includetag provided with Struts
8/2/2019 Struts Intro Course by Kamalakar Dandu
31/77
Project Refinery, Inc. 31
STRUTS View Components
Page Composition with Includes continued There are three types of includeavailable,
depending on when you want the combination ofoutput to occur: An directive can include a
file that contains java code or jsp tags
The include action() is processed at request time, and ishandled transparently by the server
The bean:include tag takes either a an argument"forward" representing a logical name mapped to the jspto include, or the "id" argument, which represents a pagecontext String variable to print out to the jsp page
http://../Java%20Docs/STRUTS/Docs/struts-bean.htmlhttp://../Java%20Docs/STRUTS/Docs/struts-bean.html8/2/2019 Struts Intro Course by Kamalakar Dandu
32/77
Project Refinery, Inc. 32
Controller Components
Unit 4
8/2/2019 Struts Intro Course by Kamalakar Dandu
33/77
Project Refinery, Inc. 33
STRUTS Controller Components
Struts includes a Servlet thatimplements the primary function ofmapping a request URI to anAction
class (ActionServlet)
8/2/2019 Struts Intro Course by Kamalakar Dandu
34/77
Project Refinery, Inc. 34
STRUTS Controller Components
Your primary responsibilities are: Write anAction class (that is, an extension of the
Action class) for each logical request that may bereceived
Write the action mapping configuration file (inXML) that is used to configure the controllerservlet (struts-config.xml)
Update the web application deployment descriptor
file (in XML) for your application to include thenecessary Struts components
Add the appropriate Struts components to yourapplication
8/2/2019 Struts Intro Course by Kamalakar Dandu
35/77
Project Refinery, Inc. 35
STRUTS Controller Components
Action Classes:
TheAction class defines a perform method
that you override
public ActionForward perform(ActionMapping
mapping, ActionForm form, HttpServletRequest
request, HttpServletResponse response)
throws IOException, ServletException;
8/2/2019 Struts Intro Course by Kamalakar Dandu
36/77
Project Refinery, Inc. 36
STRUTS Controller Components
The goal of anAction class is to
process this request, and then to returnanActionForward object that identifies
the JSP page (if any) to which controlshould be forwarded to generate thecorresponding response
8/2/2019 Struts Intro Course by Kamalakar Dandu
37/77
Project Refinery, Inc. 37
STRUTS Controller Components
A typicalAction class will implement thefollowing logic in its perform() method Validate the current state of the user's session
If validation has not yet occurred, validate the formbean properties as necessary
Perform the processing required to deal with thisrequest
Update the server-side objects that will be used to
create the next page of the user interface Return an appropriateActionForward object that
identifies the JSP page to be used to generate thisresponse, based on the newly updated beans
8/2/2019 Struts Intro Course by Kamalakar Dandu
38/77
Project Refinery, Inc. 38
STRUTS Controller Components
Design issues to remember when codingAction classes include the following The controller Servlet creates only one instance of
yourAction class, and uses it for all requests.Thus, you need to code yourAction class so that itoperates correctly in a multi-threadedenvironment, just as you must code a Servlet'sservice() method safely
The most important principle that aids in thread-safe coding is to use only local variables, notinstance variables, in yourAction class
8/2/2019 Struts Intro Course by Kamalakar Dandu
39/77
Project Refinery, Inc. 39
STRUTS Controller Components
Design issues to remember when codingAction classes include the followingcontinued The beans that represent the Model of your
system may throw exceptions due to problemsaccessing databases or other resources. Youshould trap all such exceptions in the logic of yourperform() method, and log them to the application
logfile As a general rule, allocating scarce resources and
keeping them across requests from the same user(in the user's session) can cause scalabilityproblems
8/2/2019 Struts Intro Course by Kamalakar Dandu
40/77
Project Refinery, Inc. 40
STRUTS Controller Components
The ActionMapping Implementation type - Fully qualified Java class name of theAction
implementation class used by this mapping.
name - The name of the form bean defined in the config
file that this action will use path - The request URI path that is matched to select
this mapping. See below for examples of how matchingworks.
unknown - Set to true if this action should be configuredas the default for this application, to handle all requests
not handled by another action. Only one action can bedefined as a default within a single application.
validate - Set to true if the validate() method of the actionassociated with this mapping should be called.
8/2/2019 Struts Intro Course by Kamalakar Dandu
41/77
Project Refinery, Inc. 41
STRUTS Controller Components
The Actions Mapping Configuration File
The developer's responsibility is to create an XMLfile named struts-config.xml, and place it in the
WEB-INF directory of your application The outermost XML element must be
Inside of the element, there two
important elements that you use to describe youractions:
8/2/2019 Struts Intro Course by Kamalakar Dandu
42/77
Project Refinery, Inc. 42
STRUTS Controller Components
This section contains your form beandefinitions. You use a element foreach 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 formbean
8/2/2019 Struts Intro Course by Kamalakar Dandu
43/77
Project Refinery, Inc. 43
STRUTS Controller Components
This section contains your action definitions. Youuse an element for each of your actionsyou 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 Actionclass
name: The name of your element to usewith this action
8/2/2019 Struts Intro Course by Kamalakar Dandu
44/77
Project Refinery, Inc. 44
STRUTS Controller Components
One more section of good use is the section, which specifies data sourcesthat your application can use.This is how youwould specify a basic data source for your
application inside of struts-config.xml:
8/2/2019 Struts Intro Course by Kamalakar Dandu
45/77
Project Refinery, Inc. 45
STRUTS Controller Components
The Web Application DeploymentDescriptor
The final step in setting up the application
is to configure the application deploymentdescriptor (stored in file WEB-INF/web.xml)
to include all the Struts components that
are required
8/2/2019 Struts Intro Course by Kamalakar Dandu
46/77
Project Refinery, Inc. 46
Tag Libraries
Unit 5
8/2/2019 Struts Intro Course by Kamalakar Dandu
47/77
Project Refinery, Inc. 47
STRUTS Tag Libraries
HTML Tags
Bean Tags
Logic TagsTemplate Tags
Custom Tags
8/2/2019 Struts Intro Course by Kamalakar Dandu
48/77
Project Refinery, Inc. 48
HTML Tags
The tags in the Struts HTML library form abridge between a JSP view and the othercomponents of a Web application. Since adynamic Web application often depends ongathering data from a user, input forms playan important role in the Struts framework.Consequently, the majority of the HTML tagsinvolve HTML forms. Other important issuesaddressed by the Struts-HTML tags are
messages, error messages, hyperlinking andinternationalization.
8/2/2019 Struts Intro Course by Kamalakar Dandu
49/77
Project Refinery, Inc. 49
HTML Tags
HTML "form" tags
button
cancel
checkboxes
file
hidden
image
multibox
password input fields radio buttons
reset buttons
HTML "form" tags
select lists withembedded
option
options submit buttons
text input fields
textareas
HTML Tags T i l HTML F
8/2/2019 Struts Intro Course by Kamalakar Dandu
50/77
Project Refinery, Inc. 50
HTML Tags Typical HTML Form
First Name
Street Address
CityState
Postal Code
HTML Tags T i l St t F
8/2/2019 Struts Intro Course by Kamalakar Dandu
51/77
Project Refinery, Inc. 51
HTML Tags Typical Struts Form
B T
8/2/2019 Struts Intro Course by Kamalakar Dandu
52/77
Project Refinery, Inc. 52
Bean Tags The "struts-bean" tag library provides substantial enhancements to
the basic capability provided by , as discussed in the
following sections:
Bean Properties - Extended syntax to refer to JavaBean properties withsimple names (same as the standard JSP tags and), nested names (a property named address.city
returns the value retrieved by the Java expression
getAddress().getCity()), and indexed names (a property namedaddress[3] retrieves the fourth address from the indexed "address"
property of a bean).
Bean Creation - New JSP beans, in any scope, can be created from avariety of objects and APIs associated with the current request, or withthe servlet container in which this page is running.
Bean Output - Supports the rendering of textual output from a bean (orbean property), which will be included in the response being created by
your JSP page.
Bean Tags
8/2/2019 Struts Intro Course by Kamalakar Dandu
53/77
Project Refinery, Inc. 53
Bean TagsTag 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
8/2/2019 Struts Intro Course by Kamalakar Dandu
54/77
Project Refinery, Inc. 54
Bean Tag Example
Logic Tags
8/2/2019 Struts Intro Course by Kamalakar Dandu
55/77
Project Refinery, Inc. 55
Logic Tags
The Logic tag library contains tags that areuseful in managing conditional generationof output text, looping over objectcollections for repetitive generation of
output text, and application flowmanagement.
Logic Tags
8/2/2019 Struts Intro Course by Kamalakar Dandu
56/77
Project Refinery, Inc. 56
Logic Tags For tags that do value comparisons (equal, greaterEqual,
greaterThan, lessEqual, lessThan, notEqual), thefollowing rules apply:
The specified value is examined. If it can be convertedsuccessfully to a double or a long, it is assumed that the ultimate
comparison will be numeric (either floating point or integer).
Otherwise, a String comparison will be performed. The variable to be compared to is retrieved, based on the
selector attribute(s) (cookie, header, name, parameter, property)
present on this tag. It will be converted to the appropriate type forthe comparison, as determined above.
A request time exception will be thrown if the specified variablecannot be retrieved, or has a null value.
The specific comparison for this tag will be performed, and thenested body content of this tag will be evaluated if thecomparison returns a true result.
Logic Tags
8/2/2019 Struts Intro Course by Kamalakar Dandu
57/77
Project Refinery, Inc. 57
Logic Tags For tags that do substring matching (match,
notMatch), the following rules apply: The specified variable is retrieved, based on the
selector attribute(s) (cookie, header, name, parameter,property) present on this tag. The variable is
converted to a String, if necessary.
A request time exception will be thrown if the specifiedvariable cannot be retrieved, or has a null value.
The specified value is checked for existence as asubstring of the variable, in the position specified bythe location attribute, as follows: at the beginning (iflocation is set to start), at the end (if location is set toend), or anywhere (if location is not specified).
Logic Tags
8/2/2019 Struts Intro Course by Kamalakar Dandu
58/77
Project Refinery, Inc. 58
Logic TagsTag 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
8/2/2019 Struts Intro Course by Kamalakar Dandu
59/77
Project Refinery, Inc. 59
Logic Tags - Example
Template Tags
8/2/2019 Struts Intro Course by Kamalakar Dandu
60/77
Project Refinery, Inc. 60
Template Tags
The Template tag library contains threetags: put, get, and insert. Put tags putcontent into request scope, which is
retrieved by a get tag in a different JSPpage (the template). That template isincluded with the insert tag.
Template Tags
8/2/2019 Struts Intro Course by Kamalakar Dandu
61/77
Project Refinery, Inc. 61
Template Tags
Insert Inserts (includes, actually) a
template. Templates are JSP pages thatinclude parameterized content. Thatcontent comes from put tags that are
children of insert tags.Put Puts content into request scope.
Get Gets the content from request scope
that was put there by a put tag.
Custom Tags
8/2/2019 Struts Intro Course by Kamalakar Dandu
62/77
Project Refinery, Inc. 62
Custom Tags
Image Broker Link Test
Custom Tags tld File
8/2/2019 Struts Intro Course by Kamalakar Dandu
63/77
Project Refinery, Inc. 63
Custom Tags tld File
doctypecom.pri.brokertag.ImageBrokerDoctypevaluetruetrue
Custom Tags Tag Class
8/2/2019 Struts Intro Course by Kamalakar Dandu
64/77
Project Refinery, Inc. 64
Custom Tags Tag Classpublic 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("keyword_parms");keyword_count = (String)
request.getAttribute("queryobject_count");iCnt ++;ht.put("QueryObject" + iCnt, value);request.setAttribute("keyword_parms", ht);request.setAttribute("queryobject_count", new String(new
Integer(iCnt).toString()));return EVAL_PAGE; }
}
8/2/2019 Struts Intro Course by Kamalakar Dandu
65/77
Project Refinery, Inc. 65
STRUTS Configuration File
Unit 6
STRUTS Configuration File
8/2/2019 Struts Intro Course by Kamalakar Dandu
66/77
Project Refinery, Inc. 66
STRUTS Configuration File
The developer's responsibility is to
create an XML file named struts-config.xml, and place it in the WEB-INF
directory of your application. This format
of this document is constrained by it'sdefinition in "struts-config_1_0.dtd". Theoutermost XML element must be
.
8/2/2019 Struts Intro Course by Kamalakar Dandu
67/77
Project Refinery, Inc. 67
STRUTS Configuration File Inside of the element, there are two important elements
that are used to describe your actions:This section contains your form bean definitions. You use a element for each form bean, which has the following importantattributes:
name: A unique identifier for this bean, which will be used toreference it in corresponding action mappings. Usually, this is alsothe name of the request or session attribute under which this formbean will be stored.
type: The fully-qualified Java classname of your form bean.This section contains your action definitions. You use an element for each of your actions you would like to define. Each actionelement 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 element to use with this
action
Struts-config.xml
8/2/2019 Struts Intro Course by Kamalakar Dandu
68/77
Project Refinery, Inc. 68
Struts config.xml
8/2/2019 Struts Intro Course by Kamalakar Dandu
69/77
Project Refinery, Inc. 69
Web Application Descriptor
File
Unit 7
8/2/2019 Struts Intro Course by Kamalakar Dandu
70/77
Project Refinery, Inc. 70
Web.xml File
The final step in setting up theapplication is to configure theapplication deployment descriptor
(stored in file WEB-INF/web.xml) toinclude all the Struts components thatare required. Using the deploymentdescriptor for the example application
as a guide, we see that the followingentries need to be created or modified.
Web xml File
8/2/2019 Struts Intro Course by Kamalakar Dandu
71/77
Project Refinery, Inc. 71
Web.xml File
imagebrokerWebactionorg.apache.struts.action.ActionServletapplicationimagebrokerWebconfigWEB-INF/struts-config.xml
Web.xml File - continued
8/2/2019 Struts Intro Course by Kamalakar Dandu
72/77
Project Refinery, Inc. 72
eb e co t ued
action*.do
index.html
Web.xml File - continued
8/2/2019 Struts Intro Course by Kamalakar Dandu
73/77
Project Refinery, Inc. 73
Web.xml File continued
WEB-INF/struts-bean.tld/WEB-INF/struts-bean.tld
WEB-INF/struts-html.tld/WEB-INF/struts-html.tld
WEB-INF/struts-logic.tld/WEB-INF/struts-logic.tld
8/2/2019 Struts Intro Course by Kamalakar Dandu
74/77
Application.properties File
8/2/2019 Struts Intro Course by Kamalakar Dandu
75/77
Project Refinery, Inc. 75
Application.properties File
error.cryptvalue.required=You must enter some text.error.lob.required=You must enter the Line of Business.error.unitnbr.required=You must enter the Unit Number.error.onbase_dns.required=You must enter the OnBase DNS.imagebroker.linkname=Project Refinery, Inc.imagebroker.title=pri Image Brokerimagebrokerlink.title=pri Image Broker Link Testimagelocationlist.title=Image Location Listimagelocationdetail.title=Image Location Detailimagelocationinsert.title=Image Location Inserterrors.header=errors.footer=
8/2/2019 Struts Intro Course by Kamalakar Dandu
76/77
Project Refinery, Inc. 76
Resources
Unit 9
Resources
8/2/2019 Struts Intro Course by Kamalakar Dandu
77/77
Resources
Main Struts Web Site http://jakarta.apache.org/struts/index.html
Struts User Guide http://jakarta.apache.org/struts/userGuide/index.html
Various Struts Resources
http://jakarta.apache.org/struts/resources.html
Ted Husted Web Site http://www.husted.com/struts/