Struts-config.xml configuration file (1)

Source: Internet
Author: User
The core of Struts is the struts-config.xml configuration file, which describes all struts components. Here includes configuring the main components and secondary components, and below is the content of the struts-config.xml containing the main elements:

One, the main elements of struts-config.xml:
<? 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>
</Data-source>
</Data-sources>

<Form-beans>
<Form-bean/>
</Form-beans>

<Global-forwards>
<Forward/>
</Global-forwards>

<Action-mappings>
<Action/>
</Action-mappings>

<Controller/>

<Message-resources/>

<Plug-in/>

</Struts-config>
Note: The order of the above elements is very important, your struts-config.xml configuration file must be configured in this order, otherwise your container will get wrong when it starts.

Second, the child element of the struts-config.xml:
1. <icon/> child element
It contains <small-Icon/> and <large-Icon/>. It serves as a graphical parent element. The content of <small-Icon/> is a 16x16 image file, the content of <large-Icon/> is a 32x32 image file. Example:
<Icon>
<Small-Icon>
/Images/smalllogo.gif
</Small-Icon>
<Large-Icon>
/Images/largelogo.gif
</Large-Icon>
</Icon>
2. <display-name/> child element
It provides the short textual description of the parent element, as follows:
<Display-Name>
Short textual discription of its parent Element
</Display-Name>
3. <description/> child element
It provides the full-length textual description of the parent element, as follows:
<Description>
Full-length textual discription of its parent Element
</Description>
4. <set-property/> sub-element
It is used to set the JavaBean attribute value set in its parent element. It is generally used in the specified genericdatasource attribute, extended actionmappings, and extended global forwards. As follows:
<Set-Property
Property = "Name of bean property"
Value = "value of bean property"/>
For example:
<Set-Property = "driverclass" value = "org. gjt. Mm. MySQL. Driver"/>
<Set-Property = "user" value = "admin"/>
<Set-Property = "maxcount" value = "4"/>
<Set-Property = "mincount" value = "2"/>
<Set-Property = "password" value = ""/>
<Set-Property = "url" value = "JDBC: mysql: // localhost: 3306/struts"/>

3. Configure the JDBC Data Source
The configuration format is as follows:
<Data-sources>
<Data-source>
<Set-Property = "driverclass" value = "fully qualified path of JDBC driver"/>
<Set-Property = "url" value = "data source URL"/>
<Set-Property = "mincount" value = "the minimum number of connections to open"/>
<Set-Property = "password" value = "the password used to create connections"/>
<Set-Property = "user" value = "the username used to create connections"/>
</Data-source>
</Data-sources>
The attributes and descriptions of <data-source> are as follows:
Description
The index key of the datasource instance bound to the servletcontext. If this parameter is not set, the default value is action. data_source_key. If there is more than one datasource In the application, the key value must be set.
The JDBC driver class used by driverclass (required), for example, Com. Microsoft. JDBC. sqlserver. sqlserverdriver
The jdbc url used by the URL (required), for example, JDBC: Microsoft: sqlserver: // x000088: 1433.
The maximum number of connections opened at the same time by maxcount. The default value is 2 (optional)
Minimum number of connections opened at the same time in mincount. The default value is 1 (optional)
Username (required) for connecting the user to the database)
Password: Password (required) used to connect to the database)
Description about datasource (optional)
If readonly is set to true, the link is read-only. The default value is false. (Optional)
Maximum allowed time for logintimeout to create a link, in seconds. (Optional)
If autocommit is true, it will be forcibly rolled back after each execute. The default value is true. (Optional)
Example:
<Data-sources>
<Data-source>
<Set-Property = "key" value = "value =" wiley_data_source "/>
<Set-Property = "driverclass" value = "org. gjt. Mm. MySQL. Driver"/>
<Set-Property = "url" value = "JDBC: mysql: // localhost/wileyusers"/>
<Set-Property = "maxcount" value = "5"/>
<Set-Property = "mincount" value = "1"/>
<Set-Property = "user" value = "sa"/>
<Set-Property = "password" value = "yourpassword"/>
</Data-source>
</Data-sources>

4. Configure formbean
<Form-bean/> is used to define the formbean instance to be bound to the action. Syntax:
<Form-beans>
<Form-bean name = "name used to uniquely identify a formbean"
Type = "fully qualified class name of formbean"/>
</Form-beans>
Example:
<Form-beans>
<Form-bean name = "lookupform" type = "Wiley. lookupform"/>
</Form-beans>

5. Configure Global Forwarding
Global Forwarding can define several <forward/> sub-elements. Struts first finds the corresponding <forward> In the <action-mappings> element. If it cannot be found, go to Global Forwarding configuration. Syntax:
<Global-forwards>
<Forward name = "unique target identifier"
Path = "context-relative path to targetted resource"/>
</Global-forwards>
In addition to the name and path attributes, there is also a redirect attribute. If redirect is set to true, httpservletresponse is used. sendredirect () method. Otherwise, use requestdispatcher. forward () method. The default value is false.
NOTE: If it is true, use the httpservletresponse. sendredirect () method. The value stored in the original httpservletrequest will be lost.
Example:
<Global-forwards>
<Forward name = "success" Path = "/welcome. jsp"/>
<Forward name = "failure" Path = "/index. jsp"/>
</Global-forwards>
6. Configure <action-mappings>
It can define several <action/> child elements. It mainly defines the action instance to the actionservlet class. The syntax is as follows:
<Action-mappings>
<Action Path = "context-relative path mapping action to a request"
Type = "fully qualified class name of the action class"
Name = "the name of the form bean bound to this action">
<Forward name = "forwardname1" Path = "context-relative path"/>
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.