Struts tag-Logic

Source: Internet
Author: User

The logic tag of Struts can be used to determine the content of a webpage based on specific logic conditions, or traverse the set elements cyclically. It is the most common three tags for struts applications, such as HTML and bean. its function is mainly to compare operations, perform string matching, determine whether the specified content exists, traverse the set cyclically, and forward and redirect requests. The following describes the purpose of the tag:

<Logic: equal> the variable is equal to the specified constant.

<Logic: notequal> the variable is not equal to the specified constant.

<Logic: lessthan> the variable is smaller than the specified constant.

<Logic: lessequal> the variable is smaller than or equal to the specified constant.

<Logic: geraterthan> the variable is greater than the specified constant.

<Logic: geraterequal> the variable is greater than or equal to the specified constant.

These labels are similar. They have common attributes. Cookie attributes specify the value of cookie attributes and compare them with constants set by value. set the value of the header request header in the header attribute and compare the value set in the value attribute. set a request parameter for the parameter attribute, and then compare the values set by the value attribute. set a variable for the name attribute and compare it with the value. if both the name and property attributes are set, the name attribute specifies an existing JavaBean and the property attribute specifies the bean attributes. this label is very simple and has a single usage. Next we will look at the tags for string matching and the tags for determining specific content.

<Logic: Match> A tag is used to determine whether a variable contains a constant string. <logic: netmatch> it also determines whether a variable does not contain a string. The name attribute is used to define a string variable, then, the value of the value attribute is used to determine whether the variable contains this string or does not contain this string, and true is returned for success.

The <logic: Empty> and <logic: netempty> labels can be used to determine whether the specified variable is a Null String. The name attribute can be used to determine whether a string is null. for example, it is a string of request parameters.

The <logic: Present> and <logic: notpresent> labels can be used to determine whether the specified object is null. This label has many attributes. determine whether a cookie exists. determine whether the htpp Request Header exists. the role attribute is used to determine whether the user with the current permission is a specified security role. the user attribute is used to determine whether the user currently passes permission verification has the specified user name. the parameter attribute is used to determine whether the request parameter exists. the name attribute is used to determine whether the specified bean exists. setting the name and property attributes at the same time is to determine whether the specific attributes of the bean exist.

The <logic: messagespresent> and <logic: messagesnotpresent> labels are used to determine whether a specific actionmessages within the request range or a subclass of actionerrors objects. the name attribute is used to retrieve the key of the actionmessages object. The Property specifies to retrieve a Message key from the actionmessages collection object, that is, the specific actionmessage object.

Looping the logic tag is the most complex tag in the logic tag Library and the most widely used tag. It can traverse all elements in an array, collection, enumeration, irerator, or map in a loop.

1) The name attribute of the tag <logic: iterate> Of The traversal set specifies the set object to be traversed. It retrieves an element from the set each time and stores it in the page range, specify the string with the ID attribute to name this element. It is best to nest A <Bean: Write> tag in it to output the string specified by the first Id just traversed, then in the loop output. the number of elements to be traversed by the Length attribute. If the Length attribute is not set, all elements in the set are traversed. the offset attribute specifies the actual position where the traversal starts. The default value is 0. the indexid attribute defines a series number that represents the currently traversed element. This variable is stored in the page range and can be accessed by the <Bean: Write> label to output int numbers. for example, 1.2.3.4. the serial number of the elements output by the user.

2) traversing a map uses the <logic: iterate> label. The name attribute specifies a hashmap, which is stored in the request range and assigned to the variable specified by the ID. indexid can specify the index number, then output the data using the <Bean: Write> label. each element in hashmap is a collection object, so it can be nested. that is to say, the <logic: inerate> label can generate the collection element to be negative to a variable or map. therefore, it has powerful functions. you can also set an expression for the collection attribute. The result returned by this expression can be a set of <logic: inerate> label output or map. this property is similar to the name property.

Finally, we will study the logic labels for request forwarding and redirection. The <logic: Forward> label is used for request forwarding. Its name attribute specifies the forwarding target, matches the <global-forwards> element and the <forward> element in the struts configuration file. simply put, the value defined by the name attribute of the <logic: Forward> tag is to find the matched name attribute of the <golbal-forwards> sub-element <forward> element, then forward the data through the path specified by path. for redirection, the <logic: redierct> label forward, href, and page attributes specify the redirection target. These attributes are similar to the attribute usage of the <HTML: link> label.

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.