Struts framework
The Struts framework has the advantages of module, flexibility, and reuse of the components, and simplifies the development of MVC-based web applications.
This chapter discusses the Struts architecture in detail. We will see how Struts clearly define control, transaction logic, and appearance, simplifying the development of application processes. We will also introduce how the class provided by Struts makes development work more simple, including:
l Control the program process
l Classs that implement and execute program transaction logic
l The custom tag library makes it easier to create and verify the HTML form.
1. Struts compressed package content
Folder Jakarta-Struts-1.0.2 contains two directories, libs, and webapps. In the lib directory, you can use Struts to create an application is the required file:
file
description
JDBC2_0-stdext.jar
Contains a JDBC2.0 Optional Package API class. If we want to use the data resources provided by Struts, you need to copy this file to web-inf / lib.
Struts.jar
Contains all Java classes in Struts. Also need to copy to Web-INF / LIB
* .tld
The tag library descriptor file describes custom tags in multiple Struts tag libraries. Also copy to Web-Inf / Lib
There is a file under the WebApps directory:
Web application
description
Struts-blank.war
A simple web application
Struts-docuumentation.war
Contains all Struts documents on the Struts site
Struts-esample.war
Struts a lot of features demonstration
Struts-EXERCISETAGLIB.WAR
Mainly used to increase the test page for custom label libraries, but can also demonstrate how to use Struts tags
Struts-template.war
Introduction and examples of Struts template tags
Struts-upload.war
A simple example, demonstrate how to use the struts framework upload file
2.Struts architecture
Let us observe the components in the Struts frame from the angle of the MVC
Three parts of the frame: model, window and controller.
model
In the Struts framework, the model is divided into two parts:
l system internal state
l You can change the status of the status (transaction logic)
The internal state is usually represented by a set of ActInform JavaBean. These beans may be self-contained and have a continuous state depending on the design or application complexity, or data (from a database) is only available when needed.
Large applications are typically encapsulated transaction logic (operation) in method, which can be called the bean call. For example, shopping cart bean, it has information about purchasing goods, there may be a checkout () method to check the user's credit card, and send information to the warehouse.
In a small program, the operation may be embedded in the Action class, which is part of the controller role in the Struts framework. This method is very suitable when logic is simple.
It is recommended that users separate transaction logic (what to do) with the role (decision to do) played by the Action class.
Windows
Established by JSP, Struts contains extended custom label libraries to simplify the process of created a fully international user interface.
Controller
In Struts, the basic controller component is an instance servert in the ActionServlet class, and the actually used servlet is defined by a set of mappings (described by the ActionMApping class) in the configuration file.
3. Components in the Struts framework
(Because the ROSE tool has not been downloaded, only this picture, it illustrates a certain problem, especially ActionerRors, but it does not use the ActionMApping, JSP, and Tag Library, and have a time-finished replacement) framework. Components used:
ACTIONSERVLET
Controller
ActionClass
Contains transaction logic
Actionform
Display module data
ActionMapping
Help the controller to map the request to the action
ActionForward
Objects used to indicate operational transfer
Actionerror
Used to store and recycle errors
Struts tag library
Can reduce the development of development display hierarchy
Let's take a look at the roles and responsibilities they play in the framework.
3.1 Struts Profile
This is the strew-config.xml that combines the Struts component: struts-config.xml. Defaults
/Web-inf/struts-config.xml. Profiles can be defined:
l Global forward
l actionmapping class
l actionform bean
l JDBC data source
Configure global forwarding
Global forwarding is used to create logical name mappings between JSP pages. Forwarding can be obtained by an instance that calls an operation map, for example:
ActionMappingInstace.FindForward ("LogicalName");
Example of global forwarding: (All example I have not explained, one is that the combination table can be understood, the second is that most of the examples from the series four, you should take a look after the experiment, then look at it)
global-forwards>
Attributes
description
Name
Global forwarded name
Path
Relative path with target URL
Configuring actionmapping
The ActionMapping object helps process control within the framework, which can map the request URI to the Action class and associate the Action class with the ActionForm bean. ActionServlet uses these mappings internally and transfers control to an instance of a specific Action class. All Action classes use the Perform () method to implement a specific application code, return an ActionForward object, including the target resource name of the response forwarding. E.g:
TYPE = "BOOKACTION" Name = "BOOKFORM" Scope = "request" INPUT = "/ createbook.jsp"> action> action-mappings> Attributes description Path The relative path of the Action class Name The name of the action bean associated with this operation Type Connect to the full name of the Action class (available) Scope Actionform bean scope (request or session) Prefix Used to match the prefix of request parameters and bean properties SUFFIX The suffix attribute used to match the request parameters and the bean property Scope domain name. Classname The fully qualified name of the class of the ActionMapping object is org.apache.struts.Action.ActionMapping INPUT Enter the path to the form, pointing to the control of the input error that occurs in the bean. Unknown Set to True, the operation will be used as the default operation as all the URIs that are not defined. Validate Set to True, before calling the Perform () method on the Action object, the ActionServlet will call the validate () method of the ACTIONFORM BEAN for input check. With Attributes description Id Id Classname The fully qualified name of the ActionForward class, the default is org.apache.struts.Action.ActionForward Name The logical name used when operating the class access ActionForward Path Path to respond to forward target resources REDIRECT If set to True, ActionServlet uses the sendredirect () method to forward resources. Configuring an actionform bean The ActionServlet uses ActionForm to save the request parameters, these beans correspond to the name in the HTTP request parameter, the controller passes the request parameters to the ActionForm bean instance, and then transfer this instance to the Action class. example: form-beans> Attributes description Id Id Classname The fully qualified name of the ActionForm bean, the default is org.apache.struts.Action.Actionformbean Name The form bean is in the name of the related scope, this property is used to associate bean with actionmapping Type Quick qualification name Configure JDBC data sources Use the Attributes description Id Id Key Action class uses this name to find a connection Type The name of the class that implements the JDBC interface The following property requires the Key = "contool" TYPE = "org.apache.struts.util.GenericDataSource" AutoCommit = "True" Description = "EXAMPLE DATA SOLRE Configuration" Driverclass = "org.test.mm.mysql.driver" Maxcount = "4" MinCount = "2" URL = "JDBC: mysql: // localhost / test" User = "struts" Password = "wrox" /> Attributes description DESCIPTION Description of data sources AutoCommit The default automatic update database mode used by the connection created by the data source Driverclass The class used by the data source is used to display the JDBC driver interface. Logintimeout Database login time limit, in seconds Maxcount Up to most established connections minCount Minimum number of connections to create Password Database Access password Readonly Create a read-only connection User Access the user name of the database URL JDBC URL By specifying the keyword name, the Action class can access the data source, such as: Javax.sql.datasource DS = servlet.finddataSource ("contool"); Javax.sql.connection con = ds.getConnection (); 3.2 ActionServlet class The controller component in the frame is an org.apache.struts.Action.ActionServlet class implementation, this class is an extension of the javax.servlet.http.httpservlet class. The Struts Controller's basic function is: 1. Intercepting the user's HTTP request 2. Map the request to the corresponding Action class, if this is the first request received by this class, the instance will be initialized Capacity. 3. Create or discover an ActionForm bean instance (see if the configuration file is defined), then transplant the request process to Bean.4. Call the perform () method of the Action instance and use Actioform Bean, Action Mapping object, Request Pass with the Response object. Such as: Public ActionForWord Perform (ActionMapping Mapping, ActionForm, httpservletRequest Request, HttpservletResponse response) 5.Perform Returns an ActionForWord object, which is connected to the appropriate JSP page. ActionServlet configuration We need to declare an actionServlet in Web.xml and configure it to be loaded. The following is an initialization parameter that can be configured: parameter Defaults description Application NULL Class for the resource collection of the app Buffersize 4096 File upload buffer size Config /Web-inf/struts-config.xml Profile location and name Content Text / html Default content type Debug 0 Program debugging level Detail 0 Level of procedures debugging details Factory NULL Message resource factory, used in internationalization interpretation of news resources FORMBEAN Org.apache.struts.Action.Actionformbean Name of the class of encapsulation Actionform bean information Forward Org.apache.struts.Action.ActionForward The name of the class of encapsulating an actionforward object information Locale True For True, a local object will be stored in the user session mapping Org.apache.struts.Action.ActionForward Name of the class of encapsulation activitymapping information MaxFilesize 250M Uploaded the maximum size of the file MultipartClass Org.apache.struts.Action.ActionForward Treat a name of the class that handles multiple pieces Nocache False Does the HTTP header want to set to disabled? NULL True Set to True, return null for invalid information keywords Tempdir A work directory for the program as a servlet parameter Processing download files is a temporary work directory for use Validate True Whether to use a new format profile Vallidating True Whether to effectively analyze the configuration file In most cases, the standard servlet can meet the needs of users. When the URI of the first received a specific request, the ActionServlet instantiates the appropriate Action class, and the ActionServlet stores a reference in servlet in the Action class instance. When instantiated, the Action class will be temporarily stored. ActionServlet also provides some methods that use the Action class to access resources such as data sources and forwarding targets. ACTIONSERVLET method ActinServlets provide a group of methods that can be used by Action objects. All information for the Struts API can be found in Struts-Documentation.war. Dynamic add or delete, these methods only affect the current instance of the application: Public Void AddFormbean (ActionformBean Formbean) Public Void RemoveFormBean (ActionformBean Formbean) Public Void Addforward (ActionForward ActionForward) Public Void RemoveForward (ActionForward ActionForward) Public void addmapping (actionMapping actionmapping) Public void removemapping (actionMapping actionmapping) Find objects according to the name: Public ActionFormBean FindFormbean (String Name) Public ActionForward FindForward (String Name) Public anctionMAPPING FINDMAPPING (String Name) Used to process data sources: Public Void AddDataSource (String Key, DataSource DS) Public DataSource FindataSource (String Key) We can also: l End an ActionServlet using the destroy () method l Use the reload () method to reload the information from the Struts profile. 3.3 ActionMApping class The relevant information mapped to a specific Action is stored in an actionMApping. ActionServelt transmits actionMApping to the Perform () method of the ActionMApping, Action will use an actionMApping's FindForward () method, this method returns an actionforward that specifies the name, so that ACTION Completed local forwarding. If you do not find a specific ACTIONFORWARD, you will return a NULL. Public ActionForward FindForward (String Name) You can dynamically add ACTIONFORWARD in the mapping: Public Void Addforward (ActionForward Forward) Map-associated form bean: public string getname () Remove the mapping attribute domain (session or request) Public string getscope () 3.4 Action class The Action class truly implements the application's transaction logic, which is responsible for processing the request. After receiving the request, the ActionServlet will: l Select the appropriate action for this request. l If you need, create an instance of an action l Call an perform () method If an ActionServlet does not find a valid map, it calls the default Action class (defined in the configuration file). If you find the ActionServlet forward to the appropriate actionMApping class, this action uses actionMapping to find local forwarding, then get an actionMApping property. The ActionServlet also transmits the ServletRequest object or HTTPServletRequest object according to the signature of the servlet environment and the overform () method. All Action classes expand the org.apache.struts.Action.Action class, and override a perform () method defined in the class. There are two perform () methods: Handling non-HTTP (general) request: Public ActionForward Perform (ActionMapping Action, ACIONFORM FORM, ServletRequest Request, ServletResponse response) THROWS IOEXCEPTION, ServletException Handle HTTP request: Public ActionForward Perform (ActionMapping Action, ACIONFORM FORM, HTTPSERVLETREQUEST REQUEST, Httpservletresponse response THROWS IOEXCEPTION, ServletException The Action class must program as "thread security" because the controller will share the plural simultaneous request to share the same instance, according to the design of the Action class, you need to pay attention to the following points: l You cannot use instances or static variables to store status information for specific requests, which share global resources across the request in the same operation. l If the resources you want to access (such as JavaBean and Session Variables) need to be protected when parallel access, then access is synchronous Method of Action class In addition to the perform () method, there is also the following methods: You can get or set the area associated with the request: Public Locale getLocale (httpservletRequest request) Public void setlocale (HttpservletRequest Request, Locale Locale) Get a message resource for your application: Public MessageResources getResources () Check if the user clicks on the "Cancel" button on the form, if yes, True will be returned: Public Boolean ISCANCELED (HTTPSERVLETREQUEST REQUEST) When an application error occurs, the Action class can store error messages using the following method: Public void saveerRORS (HTTPSERVLETREQUEST REQUEST, ActionerRors Errors) ActionError instance is used to store an error message, and store an ActionError object in the request attribute list under the error key. The JSP page can display these error messages by using the custom tag defined in the Struts tag library. We will introduce later. 3.5 Actionform class The framery assumes that the user creates an actionform bean for each form in the application, and the framework will do the following before the bean defined in the Struts-Config.xml file is called before the action class: l In the associated keyword, it checks the user session of the Bean instance for the appropriate class, if there is no Bean available in the session, it will automatically create a new bean and add it to the user's session. l For each parameter corresponding to the bean property name, the Action calls the corresponding setting method. l When Action Perform () is called, the latest ActionForm bean is transmitted to it, and the parameter value can be used immediately. ActionForm class extension org.apache.struts.Action.Actionform class, the BEAN created by program developers can include additional properties, and ActionServlet may use reflection (allowing recycling information from loaded objects) to access it. The ActionForm class provides another means of handling errors, providing two methods: Public ActionerRors Validate (ActionMappin Mapping, ServletRequest request) Public ActionerRors Validate (ActionMappin Mapping, HttpservletRequest Request) You should override the validate () method in your own bean, and set the validate of the If the returned is not NULL, and the length is greater than 0, the instance is stored in the requested attribute list according to the error key, and then the ActionServlet will be forwarded to the target pointing to the INPUT property of the configuration file If you need to perform a specific data validity check, it is best to do this in the Action class, not in the ActionForm class. Method RESET () can restore the properties of the bean to the default value: Public void reset (actionMapping mapping, httpservletRequest request) Public Void Reset (ActionMapping Mapping, ServletRequest Request) A typical actionFrom bean only has a method of setting with a read method (Getxxx) without transaction logic. Only simple input check logic, the purpose of use is to store the latest data entered in the relevant form so that the same web page can be regenerated while providing a set of error messages so that the user can modify the incorrect input data. It is really checking data validity to check the Action class or the appropriate transaction logic bean. 3.6 ActionForward class The purpose is to forward the processing results of the Action class to the destination. The Action class gets the handle of the ActionForward instance, and then use three methods to return to the ActionServlet, so we can use Findforward (): l ActionServlet obtains a global forwarding according to the name l ActionMAppin instance is transmitted to the Perform () method, and found a local forwarding according to the name The other is to call the following constructor to create an example of themselves: Public anctionforward () Public ActionForward (String Path) Public ActionForward (String Path, Boolean Redirect) 3.7 Error handling Struts provides two classes to handle errors: ActionerRRORS and ActionError, they all expand org.apache.struts.Action. ActionerRORS saves a collection of ActionError objects, each represents an independent error message. Each ActionError contains a keyword, which is mapped to the error message stored in the resource file, and this resource file is specified in the ActionServlet initialization parameter. ActionError class The ActionError class defines a set of overloaded constructors to create an error message, the first constructor method uses a string as a parameter, for example: Actionerror Error = New Actionerror ("Error.INvalid"); Example Error maps an error message in the application resource file: Error.INValid = invalid number b> If you use Another Java.Text.MessageFormat class can specify a replacement string in the message, for example: Error.invalid = invalid number {0} b> Create an error message: ActionError Error = New Actionerror ('Error.invalid', New Double (-1)); JSP page display: Invalild Number -1 There is also a wrong keyword for a specific message: Public string getKey () There is also an array of replacement strings: Public String [] getValues () ActionError class The ActionError class is not independently errors, which are always stored in the ActionerRors object. The ActionerRors object saves a collection of ActionError classes and their specific attribute values, we can use your own defined attribute value, or use ActionerRors.global_ERROR. Below is an error handling in Perform () of the typical Action class: MyForm Form = (MyForm) Form; IF (Number == -1) { ActionerroS Errors = new actionerrors (); ActionError Error = New ActionError ("Error.INvalid", New Double (-1)); Errors.Add (ActionerRors.global_Error, Error); SaveerRors (Req, Errors); String infut = mapping.getinput (); return new actionforward (input); } ActionerRors have the following useful methods: method description Clear () Clear all error messages EMPTY () If the ActionerRors object is empty, it returns true Get () Returns the error message. If there is no parameters, all information will be returned as an Iterator object. Properties () Returns the Iterator containing the name of the property, these attributes have at least one error Size () Returns the number of errors (integer) Struts tag library 4.Struts Tag Library The Struts tag library used by JSP window components consists of four types of tags: l bean tag: Manage Bean in JSP page l Logic tag: Control flow in the JSP page l HTML tag: Used to generate an HTML tag, display data in the form, program the URL using the session ID l Template tag: Use dynamic template to construct a page of normal format 4.1 bean tag This tag library contains tags for defining new beans, accessing beans, and its properties. The STRUTS framework provides a variety of custom tags to process JavaBean in the JSP page. These tags are packaged in a normal tag library, define its tag library descriptor in file struts-bean.tld. The bean tag library will define the tag in four subcategories: l Create and copy the tag of bean l Script variable definition tag l bean translation mark l Message Internationalization Mark 4.1.1 Bean Copy Mark You can define a new bean, you can copy the existing bean, you can also replicate properties from the existing bean. l Define new string constants l Copy existing beans to new defined bean objects l Copy the properties of the existing bean to create new beans Attributes description Id The newly defined bean script variable name must be set Type Define classes to introduce script variables Value Assign a new object to the script variable defined by the id attribute Name The name of the target bean. If the value of the value is not set, this property must be set. Property Name property defines the property name of the bean, used to define new beans Scope The scope of the source bean. If there is no setting, the search range is from the page scope to the application scope TOSCOPE The role of the target bean. If there is no setting, the default value is a page scope For example: Define a bean: Source bean is copied in the page scope, the request scope is another bean: Scope = "Page" Toscope = "request" /> 4.1.2 Defining the tag of scripting variables Define and generate script variables from multiple resources, including cookies, request parameters, HTTP headers, and more. The property is as follows: Attributes description Id Script variable and name of the page scope attribute to be defined Name Cookie / header / parameter name Multiple If this property sets any value, all matched cookies will accumulate and store them into a cookie [] (an array) type bean. If there is no setting, specify the first value of the cookie will be used as the value of the cookie type Value. If there is no matching cookie or value, return the default value specified by this property. E.g: The script variable name is MyCookie, the name of the cookie for creating this property is UserName. The script variable name is MyHeader, the name of the request header is accept-language. The script variable name is MyPatameter, and the name of the request parameter it saves is also myParameter. Attributes description Id Script variable and name of the page scope attribute to be defined Page An internal resource Forward ActionForward HREF Complete URL of the resource to be included E.g: The name of the script variable is MyInClude, and the response to retrieve is from the resource myjsp? X = 1. Attributes description Id Script variable and name of the page scope attribute to be defined Name Resource relative path INPUT If this property does not exist, the type of resource is a string E.g: The name of the script variable is MyResource, the name of the resource to retrieve is MyResource.xml. 4.1.3 Displaying Bean Attributes The Attributes description Name The name of the bean to be displayed Property The name of the attribute to display. If this attribute class has java.beans.propertyEditor, getastext () or TOSTRING method is called Scope BEAN's scope, if there is no setting, the search range is from the page to the application scope Filter If you set true, all special HTML characters in the properties will be converted to the corresponding entity reference Ignore If FALSE is set, a request time is abnormal when the property is found, otherwise returns NULL E.g: MyBean's property MyProperty will be displayed, the scope is a request, and if any HTML special characters are found, it will be converted to the corresponding entity reference. 4.1.4 Message markers and internationalization The STRTUS framework supports internationalization and localization. Users define their own area in their computer, when the web application needs to output a message, it will reference a resource file, all messages in this file use the appropriate language. An application may provide a lot of resource files, each file provides messages written in different languages. If you do not find the resource file of the selected language, you will use the default resource file. The Struts Framework supports internationalization uses the Internationalization and localization with STRTUS: The first step To define the name of the resource file, this file will contain all messages that will appear in the program with the default language. These messages are stored in the form of "keyword-value" as follows: Error.validation.Location = The Entered Location Is Invalid This file needs to be stored under the path of the class, and its path is to transmit to the ActionServlet as a parameter as a parameter, and the path format should comply with the standard naming specification for the full Java class. For example, if the resource file is stored in the web-inf / class directory, the file name is ApplicationResources.properties, then the parameter value that needs to be passed is ApplicationResources. If the file is in web-inf / classs / com / test, the parameter value should be com.test. ApplicationResources. In order to achieve internationalization, all resource files must be stored in the directory where basic resource files are located. The basic resource file contains messages written in the local language in the default regional language - local language. If the name of the basic resource file is ApplicationResources.Properties, the name of the resource file written in other specific languages should be ApplicationResources_xx.properties (xx is ISO code, such as English is en). So these files should contain the same keyword, but the value of the keyword is written in a particular language. The area initialization parameters of the ActionServlet must be transmitted with a TRUE value so that ActionServlet stores a region object of a particular user computer under an action.locale_key keyword in the user session. You can now run an international Web site that automatically displays in accordance with the area on the user's computer. We can also use a specific string to replace some messages, just like Java.Text.MessageFormat: Error.invalid.number = the number {0} is valid We can replace the string {0} to any number we need. Attributes description Key Define message keyword in the resource file Locale The property name of the area object stored in the user session. If no setting is set, the default is action.locale_key Bundle In the application context, the name of the properties of the resource object is stored. If this property is not set, the default value is action.Message_Keyarg0 First replacement parameter value Arg1 Second replacement parameter value Arg2 Third replacement parameter value Arg3 Fourth replacement parameter value For example: a message defined in the resource file: Info.mykey = the number in {0}, {1}, {2}, {3} We can use the following message tag: This information mark output to the JSP page will be displayed as: The NumBers Entered Area 5, 6, 7, 8 4.2 Logical Tag The mark of the logical library can be used to process appearance logic without the need to use the Scriptlet. The Struts Logic Tag library contains tags that can be conditionally generated, looped in an object collection, repeatedly generating output text, and application process control. It also provides a set of tags that handle flow control in the JSP page. These tags are encapsulated in the file named Struts-Logic.TLD. The mark defined by the logical tag library can perform the following three functions: l condition logic l repeat l Forward / redirect response 4.2.1 Conditional Logic Struts has three types of conditional logic. The first category can compare the size of the following entities and a constant: l cookie l request parameters L bean or bean parameters l request header This type of tag is listed below: mark Features Returns true if the constant is equal to the defined entity Returns true if the constant is not equal to the defined entity Returns true if the constant is greater than or equal to the defined entity Returns true if the constant is less than or equal to the defined entity Returns true if the constant is less than the defined entity Returns true if the constant is greater than the defined entity All markers of this class have the same properties Attributes description Value To make a constant constant value Cookie The name of HTTP cookie to be compared HEADER The name of the HTTP request header to be compared Parameter The name of the HTTP request parameter to be compared Name If you want to compare the properties of the bean or bean, this property represents the name of the bean. Property The name of the BEAN attribute to be compared Scope BEAN's scope, if no scope is specified, its search range is from page to the application E.g: The entered name is someamename logic: Equal> The value of the request parameter named "Name" is "Somename". The value of bean.prop is Greater Than 7 logic: greaterthan> It is determined whether there is a bean named "bean" in the scope of the page, which has a PROP attribute, whether the value of this property is greater than 7. If this property can be converted to a value, the numerical comparison is performed, otherwise the string is compared. The second type of condition tag defines two tags: l l Their function is to determine if a specific item is present before calculating the marker. The attributes and attribute values of the tag determine the item to be checked. Attributes description Cookie The cookie specified by this property will be checked. HEADER The request header specified by this property will be checked if Parameter The request parameter specified by this property will be checked if there is Name If the Property property is not set, then the bean specified by this property will be checked. If set, the bean and bean properties will be checked. Property Check if there is a specified attribute in the bean specified by the Name property Scope If the name of the BEAN is specified, this is the scope of the bean. If you do not specify a scope, the search range is from the page to the application scope. Role Check if the currently confirmed user belongs to a special role User Check if the user currently confirmed has a specific name E.g: The Bean Property Bean.prop is present logic: NOTPRESENT> The tag determines whether there is a bean named "bean" in the page scope, this bean has a PROP property. The third type of condition mark is more complicated, and these markers check the contents of the mark according to the results of the template match. In other words, these tags determine if the value of a specified item is a substring of a particular constant: l l These tags allow the JSP engine to calculate the marker main body when the matching or no discovery is found. The property is as follows: Attributes description Cookie The name of HTTP cookie to be compared HEADER The name of the HTTP header to be compared Parameter The name of the HTTP request parameter to be compared Name To compare the properties of the bean or bean, this property is the name of the user specifies the name. Location If the value of this property is set, you will match this specified location (index value). Scope If BEAN is compared, this property specifies the scope of the bean. If this parameter is not set, the search range is from the page to the application scope Property To make a comparative bean attribute name Value To make a constant constant value E.g: The parameter name is a sub-string of the string xyz from index 1 logic: match> The mark checks if the request parameter named "name" is a sub-string of "XYZ", but the sub-string must start from the "XYZ" index position 1 (that is, the sub-string must be "y" or "yz" ). 4.2.2 Repeat marker The l Use the runtime expression to return a collection of attribute sets l Define the collection as a bean and use the Name property to specify the name of the storage attribute. l Use the Name property to define a bean and use the Property property to define a BEAN property that returns a collection. The collection of current elements is defined as a bean of a page scope. The attributes are as follows, all of these properties use runtime expressions. Attributes description COLLECTION If there is no Name property set, it specifies a collection to be repeated. Id Page Scope BEAN and Script Variable Name, it saves the handle of current elements in the collection Indexed Page Scope JSP Bean Name, which contains the current index of the collection after repeated completion Length The maximum number of repetitions Name As the name of the set of beans, or a bean name, it is a collection by the property defined by the Property property. Offset Repeat the index of the start position Property Name of the BEAN attribute as a collection Scope If the bean name is specified, this property sets the BEAN's scope. If there is no setting, search range from page to application scope Type Type for the currently defined page scope bean E.g: Collection = "<% = myList%>" TYPE = "java.lang.integer" OFFSET = "1" Length = "2"> <% = currentint%> logic: Iterate> The code will use the first element in the list to repeat two elements and allow the current element to use the script variable of the page scope and the Java.lang.integer type. That is, if MYLIST contains elements 1, 2, 3, 4, etc., the code will print 1 and 2. 4.2.3 Forwarding and Redirecting Tags Forward mark Redirect tag Attributes description Forward ActionForward mapped to the resource relative path HREF Complete URL of resources Page Resource relative path Name The name of the page name, request, session, or program property of the Map type, which contains the Name-Value parameter to be added to the Redirect URL (if the Property property is not set). Or a bean name with the MAP type attribute, which contain the same information (no provosty attribute) Property The name of the BEAN attribute of the MAP type. The name of the bean is specified by the Name property. Scope If the name of the bean is specified, this property specifies the range of the search bean. If there is no setting, search range from page to application scope Paramid Define the name of a specific query parameter Paramname The name of the BEAN of the string type, which contains the value of the query parameter (if the paramproperty property is not set); or a name of a bean, its properties (specified in the paramproperty property) contains the query parameter value Paramproperty The name of the string bean property contains the value of the query parameter Paramscope Paramname defined bean search range At least one property in Forward, HREF, or PAGE is to be specified when using this tag to indicate which resource will be redirected. 4.3 HTML tag The Struts HTML tag can be roughly divided into the following functions: l Display form elements and input controls l Display error message l Display other HTML elements 4.3.1 Display Form Elements and Input Controls Struts is closely linked with the HTML form with the ActionForm Bean defined for formal operations. The name of the form input field is corresponding to the attribute name defined in the ActionForm Bean. When the form is first displayed, the input field of the form is transplanted from the ActionForm Bean. When the form is submitted, the request parameter will be transplanted to the Actionform Bean instance. All the following properties can be used to define the JavaScript event processor using the following properties that can be used to display the following properties using the following attributes used in the Attributes description Onblur Field lost focus ONCHANGE The field lost the focus and the value was changed. Onclick Field is clicked by the mouse Ondblclick Field double-click by mouse ONFOCUS Field receiving input focus OnkeyDown Fields have focus and key presses OnkeyPress Fields have focus and have keys to press and release ONKEYUP Fields have focus and have keys to be released OnMouseDown Mouse pointer points to fields and click OnMousemove Mouse pointer points to fields and moves within the field OnMouseout The mouse pointer points to the control, but the pointer moves periphery element OnMouseover The mouse pointer does not point to the field, but the pointer moves inside the element. OnMouseup The mouse pointer points to the field and releases the mouse button Other general properties that can be defined in Attributes description AccessKey Define shortcuts for accessing input fields Style Define the style of the input field STYLECLASS Define style table classes for entering fields TabINDEX Enter the tab order of the field Form mark The Attributes description Action Operation with a form. In the configuration, this operation is also used to identify an actionform bean associated with a form. ENCTYPE Code type of form HTTP method FOCUS Fields that need to initialize focus in the form Method HTTP method used in form Name The name of the Actionform Bean associated with the form. If this property is not set, the name of the bean will get OnReset from the configuration information. JavaScript event handle when forming a form OnSubmit JavaScript event handle when the form is submitted Scope Search for the range of Actionform Beans. If there is no setting, it will be obtained from the configuration file. Style Use format STYLECLASS Format form class for this element Type The full name of the Actionform Bean. If there is no setting, it will be obtained from the configuration file. E.g: html: form> The operation path associated with the form is ValidateEmployee, and the form data is passed through POST. For this form, additional information, such as the bean name type, the scope of the scope, is retrieved from the form specified by the form: form-beans> TYPE = "com.example.validateexample" Name = "Empform" Scope = "request" Input = "/ employeeinput.jsp"> action> action-maping> If the configuration file contains the above information, and requesting the URI * .do is mapped to the ActionServlet, the name, type, and scope of action-related Actionform Beans are Empform, Com.example.employeform, request. These properties can also be used. The following tags must be nested in the Button and cancellation Attributes description Property The name of the request parameter that defines the request parameter returned to the server when the form is submitted Value Tag on the button Reset and submission tag Text and text zone tag Attributes description Property Definition When the form is submitted, the name of the request parameter is sent back to the server, or the attribute name of the BEAN used to determine the current value of the text element. Name The attribute is queried by the name of the BEAN, which determines the value of the text box and the text area. If there is no setting, the name of the ActionForm associated with this embedded form is used. Attributes description Maxlength Maximum number of characters capable enabled Size The size of the text box (number of characters) Attributes Describe ROWS Number of lines in the text area COLS The number of columns in the text area Check box and check box tag Attributes description Name The name of the bean, its property is used to determine if the check is displayed in the selected state. If there is no setting, the name of the ActionFrom Bean associated with this embedded form will be used. Property The name of the check box is also the bean property name that determines if the check box is displayed in the selected status. In the case of the check box, this property must be an array. Value When the check box is selected, the value of the request parameter returned to the server E.g: A checkbox called Married, returns a "y" when the form is submitted. File tag Attributes description Name The name of the bean, its properties will determine the content displayed in the file control. If not set, the name of the ACTIONFORM BEAN associated with the embedded form will be used. Property This attribute defines the name of the request parameter sent back to the server when the form is submitted, and the bean property name used to determine the display content in the file control. ACCEPT The content type set of the server can handle. It will also filter the optional file type in the Customer Browser dialog. Value The tag on the button, this button can browse the file in the local file system Single button tag Attributes description Name The name of the bean, its property is used to determine if the radio button is displayed in the selected status. If there is no setting, the name of the ActionFrom Bean associated with this embedded form will be used. Property When the form is submitted back to the name of the request parameter of the server, and the name of the bean property used to determine whether the radio button is displayed in the selected state Value When the radio button is selected, return to the value of the server Hidden tag Attributes description Name The name of the bean, its property is used to determine the current value of hidden elements. If there is no setting, the name of the ActionFrom Bean associated with this embedded form will be used. Property Define the name of the request parameter sent back to the server when the form is submitted, and the name of the bean property used to determine the current value of the hidden element Value Use to initialize the value hidden input elements Password mark Attributes description Maxlength Maximum number of characters capable enabled Name The name of the bean, its attribute will be used to determine the current value of the password element. If there is no setting, the name of the ActionFrom Bean associated with this embedded form will be used. Property Defines the name of the request parameter sent back to the server when the form is submitted, and the name of the bean property used to determine the current value of the password element REDISPLAY When this field is displayed, if the corresponding bean property has been set, this property determines whether the content displaying the password. Size Size of field Select tag Attributes description Multiple Indicates whether this selection control allows multiple elections Name The name of the bean is determined which one is determined. If there is no setting, the name of the ActionFrom Bean associated with this embedded form will be used. Property Define the name of the request parameter sent back to the server when the form is submitted, and the name of the bean property used to determine which option needs to be selected Size Number of options that can be displayed at the same time Value Used to indicate the options that need to be selected Option tag (this element needs to be nested in Attributes description COLLECTION The name of the bean collection is stored in the properties of a scope. The number of options is the same as the number of elements in the collection. The Property property can define the bean properties used by the option value, and the LabelProperty property defines the properties of the bean used by the option mark. Labelname The bean used to specify a scope of action, this bean is a collection of strings, which can define the marks of the Labelproperty When using the Collection property, it is used to define the bean stored in a scope. This bean will return a string collection that can be used to write the value attribute of Name If this is the only specified property, it defines the bean stored in a scope. This bean will return a string collection that can be used to write the value attribute of Property This property defines the NAME properties of each independent bean to display the option value when using the Collection attribute. If it is not used together with the Collection property, this property defines the property name (if there is a Name property) specified by the Name property, or defines an actionform bean, this bean will return a collection to write an option value. Let's take a look at some examples of this tag: Labelproperty = "optionLabel" /> The tag assumes that there is a collection of optioncollection in a scope that contains some independent beans with optionValue properties, each with the value of an option. The flag of each option is defined by the BEAN's OptionLabel property property. OptionValues represents a bean stored in a scope, it is a string collection that can be used to write an option value, while OptionLabels represents a bean stored in a scope, it is also a string A collection that can be used to write an option sign. 4.3.2 Display the mark of the error message By defining the Property property to filter the message to display, the value of this attribute should correspond to the keyword of the ActionError object in the ActionerRROR object. The property is as follows: attribute description Bundle Represents the name of the application scope attribute, which contains message resources, its default value acion.Message_Key Locale Represents the name of the session scope attribute, which stores the area information of the user's current login. Its default is Action.Error_Key Name Indicates the name of the request attribute, which stores an ActionerRors object. Its default is Action.Error_Key Property This property specifies the keywords for storing each individual ActionError object in the ActionerRors object, which can be filtered example: Display all errors in the collection. Shows errors stored in miss.name keywords. 4.3.3 Other HTML tags The Struts HTML tag also defines the following tags to display other HTML elements: l l l l For details of these tags, please refer to the Struts documentation. 4.4 Template tag The dynamic template is a powerful means of modular web page layout design. The Struts Template Tag Library defines custom tags to implement dynamic templates. Insert tag Placement mark Attributes description Content Define what you want to insert, such as a JSP file or an HTML file Direct If this is set to true, the content specified by the Content property will be displayed directly on JSP instead of being included. Name The name of the content to be inserted Role If this property is set, the content can be performed only when the current legitimate user has a specific role. Get marker Use the Attributes description Name The name of the content inserted by Role If this property is set, the content can be performed only when the current legitimate user has a specific role. Use template tag First write a template JSP page, it will be used by all web pages: <% @ Taglib Uri = "/ Template" prefix = "template"%> hEAD>