The Struts Tag Library used by the Struts tag Library JSP window component consists of four types of tags: 1. Bean tag: Manage Bean 2. Logical tag: Used to control flow in JSP page 3. HTML tag: use To generate an HTML tag, display data in the form, programming the URL using the session ID 4. Template tag: Use the dynamic template to construct a normal format page 1, the bean tag this tag library contains the new bean, access bean, The attribute is marked. 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. Bean Tag Library Defines the tag in four subcategories: Create and copying the BEAN's tag script variable definition tag Bean translation mark message Internationalization Tag 1.1 Bean replication tag can define a new bean, you can copy the existing bean, you can also use the existing bean Copy the properties. Tags Used: Define new string constants to copy existing beans to new defined bean objects to copy existing beans's properties to create new bean tag properties: Property Description ID New Definition The bean script variable name, you must set the Type Define the class value of the introduction of the script variable to assign a new object Name target bean with the script variable defined by the id attribute. If the value attribute is not set, this property must set the properties name of the Bean defined by the Property Name property to define the scope of the new Bean 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: Defining a bean: source bean is copied in the page scope to the requesting domain Another bean: 1.2 Define script variables define and generate script variables from multiple resources, including Cookie, request parameters, HTTP headers, etc. The attributes are as follows: Property Description ID Script Variables and Type Name of Page Scheme Attributes To Define Name Cookie / Header / Parameters Multiple If this property sets any value, all matched cookies will be accumulated and stored into a cookie [ ] (An array) type bean. If there is no setting, specifying the first value of the cookie will be used as a value of the cookie type. VALUE, if there is no matching cookie or value, return this property specified by the default value, for example: The script variable name is MyCookie, the name of the cookie used to create this property is UserName. script variable name is MyHeader, the name of the request header is accept-language. script The variable name is MyPataMeter, which saved the name of the request parameter is also myParameter. tag will retrieve a resource response and introduce a script variable and string type Page Scope Properties.
This resource can be a page, an ActionForward or an external URL. Unlike , the resource response is stored in the bean of a page scope, not written to the output stream. The attributes are as follows: Property Description ID Script Variables and Page Scheme Attributes To Define Page An Action Forward This ActionForward HREF The full URL of the resource to include, for example: The name of the script variable is Myinclude, and the response to retrieve comes from the resource myjsp? X = 1. Tag will retrieve resources in the web application and introduce a script variable and page scope attribute of the InputStream or string type. If a problem occurs while retrieving resources, an exception is generated. The property is as follows: Property Description ID Script Variable and the name of the page Scheme attribute to be defined Name Resource relative path INPUT If this property does not exist, the type of resource is string, for example,: The name of the script variable is MyResource, the name of the resource to retrieve is MyResource.xml. 1.3 Displaying the tag in the bean property tag library to deliver the properties of the bean to the packaged JSP page write. This tag and are similar, the properties are as follows: Properties Description Name The name of the name to display the property of the property Property's name to display. 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, a request time is generated when it is discovered, otherwise returns NULL, for example: 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. 1.4 Message markers and international Strtus framework support international 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 tag, and the support of these tasks to implement the Java2 platform using the Locale and ResourceBundle classes defined in the Java.util packet. Java.Text.MessageFormat class definitions can support messages. With this feature, developers do not need to understand the details of these classes to internationalize and set messages. 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 in the program with the default language.
These messages are stored in the "keyword-value" form, 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 should be transmitted to the ActionServlet as a parameter as an initialization parameter. When passing, the path is formatted to 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 the basic resource file is 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 strings {0} to any We need the numbers. The tag property is as follows: Properties Description The property name of the area object stored in the Key resource file 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 Arg3 The fourth replacement parameter value ARG3 The fourth replacement parameter value is defined in the resource file: Info.mykey = the number {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, the mark of the logical tag logic library can be used to process appearance logic Not need to use 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 logical tag library defined tag can perform the following three functions: Conditional logic Repeat / Redirect Response Response 2.1 Conditional Logic Struts has three types of conditional logic.
The first category can compare the following entities and a constant size: Cookie Request parameter bean or bean parameter request header below: Tag function Returns true if the constant is equal to the defined entity. Returns True if the constant is not equal to the defined entity. If the constant is greater than or equal to the defined entity, returns true Returns True if the constant is less than or equal to the defined entity. If the constant is less than the defined entity, returns True Returns true if the constant is greater than the defined entity. All marks of this class have the same attribute attribute description: Value To compare the constant value cookie to compare the HTTP cookie name Header to compare the HTTP request header of the name Parameter to compare the name of the HTTP request parameter Name If the property is to be compared, the property represents the name of the BEAN's name Property to compare the name of the name of the name Scope BEAN. If no scope is specified, its search range is from the page to Applications such as: the entered name is someame logic: Equal> is "Somename". The value of bean.prop is Greater Than 7 << logic: greaterthan> Decision is in the scope of the page A bean named "bean" 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 mark 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: Cookie The cookie specified by this property will be checked whether there is a request header specified by this property will be checked if the presence of the request parameter specified by this property will be checked whether there is a name if there is no provision attribute, then The bean specified by this property will be checked. 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 user belongs to a special role User check if the user has a specific name, for example: The bean property bean .prop is present: NOTPRESENT> 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 discovered. The attribute 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 comparison Parameter to compare the name of the HTTP request parameter to compare the properties of the bean or bean, this property Is the name where the user specifies the name Location If the value of this property is set, the specified position (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 a constant value of the bean from the page to the application scope Property to compare the constant value to compare, for example: The parameter name is a sub-string of the string xyz from index 1 logic: match> tag Check whether the request parameter named "name" is a sub-string of "xyz", but the sub-string must Starting from the "XYZ" index position (that is, the sub-string must be "y" or "yz"). 2.2 Repeat markers Define the tag in the logical tag library, which can repeat the content of the marker according to the number of elements in a particular set. The type of collection can be java.util.ITerator, java.util.collection, java.util.map, or an array. There are three ways to define this collection: 1. Use a run time expression to return a collection of attribute collections 2. Define the collection as a bean and use the Name property to specify the name of the storage attribute. 3. 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 Scheme JSP bean name, it contains The current index of the collections after repeated completion, the maximum number of NAME as a collection of bean names, or a bean name, which is defined by the Property property, is a collection of OFFSET Repeat Start Location Index Property as a collection of beans The name of the attribute 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. For example: <% = currentint%> logic : Iterate> The code will repeat two elements from the first element in the list and allow the current element to use the script variable for the pages and java.lang.integer types. That is, if MYLIST contains elements 1, 2, 3, 4, etc., the code will print 1 and 2. 2.3 Forwarding and Redirect Tag Forward Mark Tagging The response forwards to the redirect to a specific global ActionForward. The type of ActionForward determines whether to use the pageContext forward response or use SendRedirect to redirect the response. This marker has only one "name" property that specifies the name of the global ActionForward, for example: redirect tag tag is a powerful tool that can perform HTTP redirection. According to the specified different properties, it can achieve redirection in different ways. It also allows developers to specify query parameters for redirect URLs. The property is as follows: Property Description: Forward Map The ActionForward HREF resource of the resource relative path The "Request, Session, or Properties of the Name Map" page name, request, session, or program property name, containing the name to be added, redirected URL ( If you do not set the "Name-Value" parameter on the Property 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 search parameter's value 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.
Third, the HTML mark Struts HTML tag can be roughly divided into the following functions: Display Form Elements and Input Control Display Error Messages Display Other HTML Elements 3.1 Displaying Form Elements and Enter Control Struts Actionform Bean defined by HTML forms with forms of operations Close to close together. 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