The Struts Framework's Action Mappings Configuration File
The main control file in the Struts framework is the struts-config.xml XML file, where action mappings are specified. This file's structure is described by the struts-config DTD file, which is defined at http://jakarta.apache.org/struts/. A copy of the DTD can be found on the /docs/dtds subdirectory of the framework's installation root directory. The top-level element is struts-config. Basically, it consists of the following elements:
data-sourcesA set of data-source elements, describing parameters needed to instantiate JDBC 2.0 Standard Extension DataSource objects
form-beansA set of form-bean elements that describe the form beans that this application uses
global-forwardsA set of forward elements describing general available forward URIs
action-mappingsA set of action elements describing a request-to-action mapping
Each of the subelements listed is described in the next sections.
Data Sources and the data-source Element
A data-source element describes the parameters necessary to configure a JDBC 2.0 Standard Extension DataSource. These parameters are defined as attributes of the data-source element:
autoCommitThe default auto-commit state to be set when creating a new connection to the database.
descriptionA description for this data source.
driverClassThe complete Java class name of the JDBC driver to be used. This is a required attribute.
keyOnce created, this DataSource will be stored under an attribute on the application servlet context. This attribute holds the name to be used for the context's attribute. The default attribute name is specified by the Action.DATA_SOURCE_KEY String.
loginTimeoutThe maximum number of seconds to wait for a connection to be created or returned.
maxCountThe maximum number of connections to be created.
minCountThe minimum number of connections to be created.
passwordThe database password to use when connecting. This is a required attribute.
readOnlyThe default read-only state for newly created connections.
urlThe JDBC URL to use when connecting. This is a required attribute.
userThe database username to use when connecting. This is a required attribute.
The code fragment in Listing 1 describes a data-sources element with two DataSources defined.
Listing 1 - Defining DataSources in the data-sources Element
<data-sources> <data-source autoCommit="false" description="First Database Config"
driverClass=" org.gjt.mm.mysql.Driver" maxCount="4" minCount="2" password="admin" url="jdbc:mysql://localhost/ARTICLEDB" user="admin" /> <data-source autoCommit="false" description="Second Database Config" driverClass="oracle.jdbc.driver.OracleDriver" key="REFDB" maxCount="4" minCount="2" password="admin" url="jdbc:oracle:thin:@localhost:1521/AUTHORDB" user="admin" /> </data-sources>
The code fragment in Listing 1 shows a configuration with two databases: a MySQL-based ARTICLEDB database and an Oracle-based AUTHORDB database. The ARTICLEDB DataSource element is stored under the default key, the default attribute name defined by Action.DATA_SOURCE_KEY. The second database DataSource will be stored under the attribute named REFDB.