Chapter 15: The struts-config.xml File

 < Day Day Up > 



Overview

In this chapter, we discuss the file that is at the heart of the Jakarta Struts Project: the struts-config.xml file. You describe all of your Struts components within this file.

This chapter examines the configuration of the top-level Struts components, including DataSources, FormBeans, Global Exception, Global Forwards, ActionMappings, the Controller, message resources, and Plugins. We also describe each of the subordinate components available as sub-elements of the top-level Struts components.

Listing 15.1 shows a stripped-down version of the struts-config.xml file. This example shows all of the top-level components of a Struts configuration file.

Listing 15.1: The struts-config.xml file.

start example
 <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> <struts-config>   <data-sources>     <data-source       type="org.apache.commons.dbcp.BasicDataSource">       <set-property property="driverClassName"         value="com.mysql.jdbc.Driver" />       <set-property property="url"         value="jdbc:mysql://localhost/stocks" />       <set-property property="username"         value="YOUR USERNAME" />       <set-property property="password"         value="YOUR PASSWORD" />     </data-source>   </data-sources>   <form-beans>     <form-bean name="registrationForm"       type="com.wrox.RegistrationForm"/>   </form-beans>   <global-exceptions>     <exception       key="com.wrox.error"       type="java.io.Exception"       handler="com.wrox.ExceptionHandler">   </global-exceptions>   <global-forwards>     <forward name="registration" path="/registration.jsp"/>   </global-forwards>   <action-mappings>     <action path="/saveRegistration"       type="com.wrox.SaveRegistrationAction"       name="registrationForm"       scope="request"       input="registration"/>   </action-mappings>   <controller>     <set-property property="inputForward" value="true"/>   </controller>   <message-resources     parameter="com.wrox.ApplicationResources"/>   <plug-in className="com.wrox.plugins.ModuleConfigVerifier"/> </struts-config> 
end example

start sidebar

It is important to note the order of each of the elements in Listing 15.1. This is the order in which they must appear in the struts-config.xml file. If the order deviates from that shown in the listing, Struts throws an exception upon startup.

end sidebar



 < Day Day Up > 



Professional Jakarta Struts
Professional Jakarta Struts (Programmer to Programmer)
ISBN: 0764544373
EAN: 2147483647
Year: 2003
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net