Struts tag library
The Struts tag library used by JSP window components consists of four types of tags:
2. Bean tag: Manage Bean in JSP page
3. Logical tag: Control flow in the JSP page
4. HTML tag: Used to generate an HTML mark, display data in the form, program the URL using the session ID
5. Template tag: Construct a normal format using dynamic template
2.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:
Create and copy the tag of the bean
Script variable definition tag
Bean translation mark
Message international tag
2.1.1 Bean replication tag
You can define a new bean, you can copy the existing bean, you can also replicate properties from the existing bean.
Define new string constants
Copy existing beans to new defined bean objects
Copy the properties of the existing bean to create new beans
Property Description ID The new defined bean script variable name, you must set the Type definition to introduce the class Value of the script variable to assign a new object Name target bean name for the ID attribute defined. If the value attribute is not set, this property must set the properties name of the Bean defined by the Property Name property, used to define new beans
13
Scope of the Scope source bean. If there is no setting, the search range is the scope of the slave page scope to the application scope TOSCOPE 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" /> 2.1.2 Define 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: Property Description ID Script Variable and Type Name of Page Scheme Properties To Define Name Cookie / Header / Parameters Multiple If this property sets any value, all matched cookies are accumulated and stored in a cookie [] Array) type bean. If there is no setting, specifying the first value of the cookie will be the value of the cookie type if the value is not matched, the default value specified by this property is returned. 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. E.g: The name of the script variable is MyInClude, and the response to retrieve is from the resource myjsp? X = 1. Property description 14 ID script variable and page scope to define the name of the name 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. 2.1.3 Displaying bean properties The Property Description Name The name of the name to display by the property displayed by the property is Property. If this attribute class has java.beans.propertyEditor, getastext () or TSTRING method will call Scope Bean's scope, if no settings are set, search range is from page to application scope Filter If set true, all specials in attributes HTML characters will be converted to the appropriate entity reference IGNORE If false is set, it will generate a request time anomalies when discovered attributes, otherwise returns NULL E.g: FILTER = "true" /> 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. 2.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 a web-inf / class directory, the file name is 15 ApplicationResources.properties, 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. Property Description The property name of the area object stored in the Key resource file defines the area object stored in the LOCALE user session. If there is no setting, the default value is an action.locale_key bundle in the application context, store the name of the properties of the resource object. If this property is not set, the default value is an action.Message_Key Arg0 The 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 2.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: Conditional logic repeat Forward / Redirect Response 16 2.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: cookie Request parameters Parameters of beans or beans Request header This type of tag is listed below: Tag function All markers of this class have the same properties Property Description Value To make a comparison of the name of HTTP cookies to compare the HTTP request header of the comparison HTTP request header name Parameter To make comparison HTTP request parameters Name Name If you want to make a bean or bean Attribute, then this property represents the name of the BEAN's name Property to compare the name of the name Scope BEAN, if no scope is specified, its search range is from the 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: 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. Property description In one Cookie The cookie specified by this property will be checked whether there is a request header specified by this property by this property will be checked whether there is a request parameter specified by this attribute that the request parameter specified by this property will be checked whether there is a name if there is no Property property, then this property is available. The specified bean will be checked if it exists. If set, the bean and bean properties will be checked. Property Checks if there is a name specified by the Name property specified by the specified 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 Checks whether the current confirmed user belongs to a special role user check whether the current confirmed user 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: 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: Property Description Cookie The name of the HTTP cookie to compare Header to compare the name of the HTTP header of the HTTP header Parameter to compare the name Name to compare the name Name to compare the properties of the bean or bean, this property is the user designated The name of the bean Location If the value of this property is set, the specified location (index value) will match Scope If the bean is compared, this property specifies the scope of the bean. If this parameter is not set, the search range is the constant value of the property name Value to be compared from the page to the application scope of Property. 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" ). 2.2.2 Repeat marker The 18 Java.util.map or an array. There are three ways to define this collection: Use run time expressions to return a collection of attribute collections The collection is defined as beans and use the Name property to specify the name of the storage attribute. 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. Property Description Collection If the Name property is not set, it specifies the name of the set ID page scope to repeat the set ID page scope, which saves the name of the current element's handle indexed page Schedule JSP bean name, it contains The current index of the collections after each repeated completion, the maximum number of times Name is the name of the set of bean, or a bean name, which is defined by the Property property, is a set of Offset Repeat Start Location Index Property as a collection of bea property. Name Scope If the bean name is specified, this property sets the BEAN's scope. If there is no setting, search range from the page to the application scope type 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, the code will print 1 and 2.2.2.3 forwarding and redirect tags. Forward mark Redirect tag 19 Property Description Forward Mapping the ActionForward HREF resource of the resource relative path The relative path name, request, session, or program property of the Name Map type, which contains a big redirect URL (if no Property is set) The Name-Value parameter on the property). Or the bean name with the MAP type attribute, which contains the same information (no provosty attribute) the name of the bean property of the Property 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 search beans. If there is no setting, search range from the page to the application scope paramid define the name of the name of the specific query parameter paramname string type, which contains the value of the query parameter (if the paramproperty property is not set); or a bean name, Its property (specified in the paramproperty property) contains the name of the query parameter value paramproperty string bean property, which 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. 2.3 HTML tag The Struts HTML tag can be roughly divided into the following functions: Display form elements and input controls Display error message Show other HTML elements 2.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. The attribute description Onblur field lost the focus onchange field lost the focus and the value was changed. The onclick field was changed by the mouse Click the onfocus field by the mouse Double-click the onfocus field to receive the input focus onkeyDown field has focus and key Press 20 The onkeypress field has focus and has a key to press and release the onkeyup field to have a focus and a button is released onMousedown mouse pointer points to the field and click on the onmousemove mouse pointer points to the field and move the onmouseout mouse pointer to the control, but the pointer moves onMouseOver The mouse pointer does not point to the field, but the pointer moves the ONMOUSEUP mouse pointer inside the element points to the field, and the other general properties that can be defined in the mouse button Property Description AccessKey Defines the Shortcut Key Style Definition of the Enter Field Style StyleSyleClass Defines the Tab Index Input Field Tabindex Enter the Tab Up. a) form mark The Property Description Action is related to a form. In the configuration, this operation is also used to identify the name of the HTTP method Name and form-related Actionform Beans that require initialization focus in the encoded type FOCUS form associated with the form of an ActionForm Bean EncType form. If this property does not set this property, the name of the bean will get the JavaScript event handler when reset from the configuration information, the JavaScript event handle Scope, the JavaScript event handle, the JavaScript event handle Scope search for the range of Actionform Beans. If there is no setting, you will get the format of the format STYLECLASS for the format of the format of the Style table Type 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: twenty one 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. b) Button and cancellation Property Description Property defines the tag on the name of the request parameter that returns to the server when the form is submitted c) Reset and submitted the tag d) Text and text zone tag Property Description Property Defines the name of the request parameter that is sent back to the server when the form is submitted, or to determine the name of the reality name Name property of the text element, which determines the text box and the text area. value. If there is no setting, the name of the ActionForm associated with this embedded form is used. Property Description MaxLength's maximum number of characters entered twenty two Size text box size (number of characters) Attribute describes the number of rows of rows in the ROWS text area column number e) Check box and check box tag Attribute describes the name of the Name Bean, its property is used to determine if the check is displayed in the selected status display. If there is no setting, the name of the ActionFrom Bean associated with this embedded form will be used. The name of the Property 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 to return to the server's request parameter E.g: A checkbox called Married, returns a "y" when the form is submitted. f) file tag The property describes the name of the name bean, and 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 is defined. 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 tags on the Value button on the optional file type in the Customer Browser dialog, which can browse files in the local file system. g) radical button mark The property describes the name of the Name Bean, which is used to determine if the radio button 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 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 if the radio button is displayed in the selected state. Value Returns the value of the server when the radio button is selected h) hidden tag Property Description Name bean's name, its property is used to determine the current value of the hidden 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 value of the bean property used to determine the current value of the hidden element is used to initialize the value of hidden input elements. i) Password tag The property describes the name of the maximum number of characters that MaxLength enters the name bean, which will be used to determine the current value of the cryptographic 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 that is 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 is displayed, if the corresponding bean property has been set, this The property determines whether the size of the content size field is displayed. j) Select tag Property Description MultiPle indicates whether this selection control allows the name of the NAME BEAN, which is determined which. 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 that is sent back to the server when the form is submitted, and the name of the Name of the bean property to determine which option needs to be selected, the number of options that can be displayed simultaneously VALUE is used to indicate the option to be selected. K) Optional tag (this element needs nested in twenty four The property describes the name of the Collection Bean collection, which 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 property used by the option value, and the LabelProperty property definition option tag is used to specify the bean stored in a scope, this bean is a collection of strings and can define The tag of the element (if the flag is not the same) LabelProperty is used in common with the Collection property, and the bean stored in a scope is defined. This bean will return a string collection that can be used to write < HTML: OPTION> Element Value Attribute 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 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. 2.3.2. Display the marker 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: Property Description BUNDLE represents the name of the application scope attribute, which contains message resources. The default value ACIion.Message_Key Locale represents the name of the session scope attribute, which stores the currently logged in area information. Its default is Action.Error_Key 25 Name represents the name of the request attribute, which stores an ActionerRors object. Its default is that the activity.Error_Key Property property specifies the keywords for storing each independent ActionError object in the ActionerRORS object, which can be filtered with the message example: Display all errors in the collection. Shows errors stored in miss.name keywords. 2.3.3. Other HTML tags The Struts HTML tag also defines the following tags to display other HTML elements: For details of these tags, please refer to the Struts documentation. 2.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. 2.4.1. Insert tag 2.4.2. Place the mark Property Description Content Defines the content to be inserted, such as a JSP file or an HTML file Direct If this setting is true, the content specified by the Content property is displayed directly on the JSP instead of the name Role if the content to be inserted. This property is set, and the content can be performed only when the current legitimate user has a specific role. 26 2.4.3. Get tag Use the Property Description Name The name Role of the content inserted by the 2.4.4. Use template tags First write a template JSP page, it will be used by all web pages: <% @ Taglib Uri = "/ Template" prefix = "template"%> hEAD>