Detailed description of struts1.x configuration file

Source: Internet
Author: User

<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype Struts-config public
"-// Apache Software Foundation // DTD struts configuration 1.1 // en"
Http://jakarta.apache.org/struts/dtds/struts-config.dtd>
<! -- Elements in the struts-config.xml must be written according to the DTD document definition order in the preceding Doc instruction. In this example, the DTD definition order is followed. -->
<! -- Struts-config is the root element of the entire XML, and other elements must be included. -->
<Struts-config>
<! --
Name: Data-Sources
Description: The data-sources element defines the data source used by the web app.
Quantity: up to one
Child element: Data-Source
-->
<Data-sources>
<! --
Name: Data-Source
Description: The data-source element defines a specific data source.
Quantity: any number
Attribute:
@ Key: when multiple data sources need to be configured, it is equivalent to the data source name, which is used to differentiate data sources from each other.
@ Type: Class implemented by the data source that can be used, generally from the following four libraries
Poolman, open Source code Software
Expresso, jshortate
JDBC pool, Open Source Code Software
DBCP, Jakarta
-->
<Data-source key = "firstone" type = "org. Apache. commons. DBCP. basicdatasource">
<! --
Name: set-Property
Description: Used to set data source attributes.
Attribute:
@ Autocommit: whether to submit automatically. Optional values: True/false.
@ Description: data source description
@ Driverclass: class used by the data source
@ Maxcount: Maximum number of data source connections
@ Mincount: Minimum number of data source connections
@ User: Database User
@ Password: Database Password
@ URL: Database URL
-->
<Set-Property = "autocommit" value = "true"/>
<Set-Property = "Description" value = "Hello! "/>
<Set-Property = "driverclass" value = "com. MySQL. JDBC. Driver"/>
<Set-Property = "maxcount" value = "10"/>
<Set-Property = "mincount" value = "2"/>
<Set-Property = "user" value = "root"/>
<Set-Property = "password" value = ""/>
<Set-Property = "url" value = "JDBC: mysql: // localhost: 3306/helloadmin"/>
</Data-source>
</Data-sources>

<! --
Name: Form-beans
Description: used to configure multiple actionform beans.
Quantity: up to one
Child element: Form-bean
-->
<Form-beans>
<! --
Name: Form-bean
Description: used to configure actionform bean.
Quantity: any number
Child element: Form-Property
Attribute:
@ Classname: Specifies the configuration class corresponding to the form-bean element. Generally, org. apaceh. Struts. config. formbeanconfig is used by default. If custom, formbeanconfig must be inherited.
@ Name: Required attribute! Create a globally unique identifier for the current form-bean so that this identifier can be used to reference this actionform bean throughout the Struts framework.
@ Type: Required attribute! Specifies the complete class name that implements the current actionform bean.
-->
<Form-bean name = "hello" type = "mypack. Hello">
<! --
Name: Form-Property
Description: used to set the attributes of actionform bean.
Quantity: Depends on actual needs. For example, one login form corresponding to actionform bean has two fields: name, password, and actionform bean, write two form-properties to set attributes.
Attribute:
@ Classname: Specifies the configuration class corresponding to form-property. The default configuration class is org. Apache. Struts. config. formpropertyconfig. If it is customized, it must inherit the formpropertyconfig class.
@ Name: attribute name of the actionform bean to be set
@ Type: class of the attribute value of the actionform bean to be set
@ Initial: Initial Value of the current attribute
-->
<Form-property name = "name" type = "Java. Lang. String"/>
<Form-property name = "Number" type = "Java. Lang. iteger" Initial = "18"/>
</Form-bean>
</Form-beans>

<! --
Name: Global-Exceptions
Description: exception handling.
Quantity: up to one
Child element: exception
-->
<Global-exceptions>
<! --
Name: exception
Description: defines an exception and its handling.
Quantity: any number
Attribute:
@ Classname: Specifies the configuration class corresponding to the exception. The default value is org. Apache. Struts. config. exceptionconfig.
@ Handler: Specifies the exception handling class. The default value is org. Apache. Struts. Action. exceptionhandler.
@ Key: Specifies the Message key that describes the exception in the resource bundle.
@ Path: Specifies the forwarding path when an exception occurs.
@ Scope: Specifies the range in which the actionmessage instance is stored. The default value is request. The other value is session.
@ Type: required! Specifies the name of the exception class to be processed.
@ Bundle: Specify resource binding
-->
<Exception
Key = "" Hello. Error
Path = "/error. jsp"
Scope = "session"
Type = "Hello. handleerror"/>
</Global-exceptions>

<! --
Name: Global-forwards
Description: Global Forwarding is defined.
Quantity: up to one
Child element: Forward
-->
<Global-forwards>
<! --
Name: Forward
Description: defines a specific forwarding rule.
Quantity: any number
Attribute:
@ Classname: Specifies the configuration class corresponding to the forward element. The default value is org. Apache. Struts. Action. actionforward.
@ Contextrelative: If this parameter is set to true, the current context is used. The path starts with "/". The default value is false.
@ Name: required! Unique Identifier of the specified forwarding path
@ Path: required! Indicates the forwarding or redirection Uri. It must start. The specific configuration must correspond to contextrelative.
@ Redirect: if it is true, the redirection operation is executed; otherwise, the request is forwarded. The default value is false.
-->
<Forward name = "A" Path = "/a. jsp"/>
<Forward name = "B" Path = "/Hello/B. Do"/>
</Global-forwards>

<! --
Name: Action-mappings
Description: defines the action set.
Quantity: up to one
Child element: Action
-->
<Action-mappings>
<! --
Name: Action
Description: defines the ing from a specific request path to the corresponding action class.
Quantity: any number
Child element: exception, forward (both are local values)
Attribute:
@ Attribute: Specifies the name (key) of the actionform bean associated with the current action within the range of request and session)
@ Classname: configuration class corresponding to the action element. The default value is org. Apache. Struts. Action. actionmapping.
@ Forward: indicates the URL path forwarded by the name.
@ Include: indicates the URL path included in the name.
@ Input: indicates the URL path containing the input form. If form verification fails, the request will be forwarded to this URL.
@ Name: Specifies the name of the actionform bean associated with the current acion. This name must be defined in the form-bean element.
@ Path: Specifies the path to access the action. It starts with "/" and has no extension.
@ Parameter: configure the parameter for the current action. You can obtain the parameter by calling the getparameter () method of actionmapping in the action execute () method.
@ Roles: Specifies the security role that allows the aciton to be called. Multiple roles are separated by commas. When processing a request, requestprocessor determines whether the user has the permission to call this action based on this configuration item.
@ Scope: Specifies the scope of the actionform bean. Optional values: request and session. The default value is session.
@ Type: Specifies the complete Class Name of the action class.
@ Unknown: If the value is true, all invalid action URLs sent by the user can be processed. The default value is false.
@ Validate: Specifies whether to call the validate () method of actionform Bean first. The default value is true.
Note: In the preceding attributes, forward/include/type is mutually exclusive, that is, only one of the three can exist in the same action configuration.
-->
<Action Path = "/search"
Type = "addressbook. Actions. searchaction"
Name = "searchform"
Scope = "request"
Validate = "true"
Input = "/search. jsp">
<Forward name = "success" Path = "/display. jsp"/>
</Action>
</Action-mappings>

<! --
Name: Controller
Description: used to configure actionservlet.
Quantity: up to one
Attribute:
@ Buffersize: Specifies the buffer size for input files to be uploaded. The default value is 4096.
@ Classname: Specifies the configuration class of the current controller. The default value is org. Apache. Struts. config. controllerconfig.
@ Contenttype: specifies the content type and character encoding of the corresponding result.
@ Locale: Specifies whether to save the locale object to the current user's session. The default value is false.
@ Processorclass: Specifies the complete Class Name of the Java class responsible for processing requests. The default is org. Apache. Struts. Action. requestprocessor.
@ Tempdir: Specifies the temporary working directory when the file is uploaded. If not set, the servlet container will be used to assign a temporary working directory to the Web application.
@ Nochache: true: add the specific header parameters pragma, cache-control, and expires to the results to prevent the pages from being stored in the cache of a handful of browsers. The default value is false.
-->
<Controller
Contenttype = "text/html; charsets = UTF-8"
Locale = "true"
Processorclass = "customrequestprocessor">
</Controller>
<! --
Name: Message-Resources
Description: Configure resource bundle.
Quantity: any number
Attribute:
@ Classname: Specifies the configuration class corresponding to message-resources. The default value is org. Apache. Struts. config. messageresourcesconfig.
@ Factory: Specifies the factory class of the resource. The default value is org. Apache. Struts. util. propertymessageresourcesfactory.
@ Key:
@ NULL:
@ Parameter:
-->
<Message-Resources
Null = "false"
Parameter = "defaultresource"/>
<Message-Resources
Key = "Images"
Null = "false"
Parameter = "imageresources"/>

<! --
Name: plug-in
Description: struts plug-in configuration.
Quantity: any number
Child element: set-Property
Attribute:
@ Classname: Specifies the struts plug-in class. This class must implement the org. Apache. Struts. Action. plugin Interface
-->
<Plug-in
Classname = "org. Apache. Struts. validator. validatorplugin">
<! --
Name: set-Property
Description: configure the attributes of the plug-in.
Quantity: any number
Attribute:
@ Property: the property name of the plug-in.
@ Value: the value configured for this name.
-->
<Set-Property
Property = "pathnames"
Value = "/WEB-INF/validator-rules.xml,/WEB-INF/vlaidation. xml"/>
</Plug-in>

</Struts-config>
1. Configure web. XML for struts
1. Configure actionservlet (only one) to receive the application Program All received requests
Two steps: A: configure the servlet instance using the servlet element for servlet-mapping.
<Web-app>
<Servlet>
<Servlet-Name> storefront </servlet-Name>
<Servlet-class> fully qualified class name </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> storefront </servlet-Name>
<URL-pattern> *. DO </url-pattern>
</Servlet-mapping>
</Web-map>
2. Configure the initialization parameter: init-Param, which is represented by name/value. <param-Name> <param-value>
Config: default/WEB-INF/struts-config.xml
Config/sub1: config/... from the attached struts configuration file, add sub1 to the asset Program
Debug: servlet debugging detail
Detail: Debug detail of Digester
Converthack
3. <taglib> the tag library provided by struts must be configured to include
<Taglib-Uri> the tag library used by Web applications must be valid.
<Taglib-location> specifies the location of the library description file.
4. The <welcome-file-List> configuration is valid in the web app, but the default resource used by incomplete URLs is not used. servlet ing is not used.
<Welcome-File> no start or end symbol/
5, <error-page>
(<Error-code> <location>)
<Exception-type> <location>
</Error-page>

Ii. Struts configuration file
Applicationconfig: contains all information in the struts configuration file.
1, <data-source>
<Set-Property = "" value = ""/>
<Data-source>
2, <form-beans>
<Form-bean name = "loginform" type = "fully qualified class name, which is a subclass of actionform">
<Form-property name = "" type = ""/>
</Form-bean>
<Form-bean
</Form-beans>
3, <global-exceptions>
4, <global-forwards>

The <data-sources> label has been removed in struts1.3, meaning it can only be configured in version 1.2, because Apache does not recommend configuring the data source in the struts-config.xml. Therefore, we recommend that you do not configure the data source in struts. If you use hibernate or spring, you can configure the data source in the hibernate configuration file or spring file. If no data source is used, configure it in Tomcat. 

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.