1.logic:empty
The logic:empty tag is used to determine whether it is empty. If empty, the content embedded in the tag body will be processed. This tag is used in the following situations:
When the Java object is null When the String object is "" When isEmpty() in the java.util.Collection object returns true When isEmpty() in the java.util.Map object returns true The following code example illustrates the logic: The empty tag determines whether the collection persons is empty:
<logic:empty name="listForm" property = "persons">
<div>The collection persons is empty!</div>
</logic:empty>
2.logic:notEmpty
The application of this tag is exactly the opposite of the logic:empty tag.
3.logic:equal
This tag is the equals comparison operator.
eg1. Compare the user's status attribute to see if it is 1. If it is 1, output "enabled";
eg2. If the value in the above example is obtained dynamically, for example, it needs to be output through bean:write, because struts does not support label nesting, EL can be used to solve this problem.
logic:equal
What we want to introduce here is not just the logic:equal(=) tag, but a type of tags that complete comparison operations, including:
logic:equal(=)
logic:notEqual(!=)
logic:greaterEqual(>=)
logic:lessEqual(<=)
logic:graterThan(>)
logic:lessThan(<)
The usage of this type of tag is similar. We only introduce the logic:equal tag and leave the rest to you.
logic:equal is used to determine whether they are equal. If equal, the content embedded in the tag body will be processed. This tag is used in the following situations:
Compares whether the value of the cookie specified by the cookie attribute of this tag is equal to the value of the value attribute of this tag.
Compares whether the value of the header specified by the tag's header attribute is equal to the value of the tag's value attribute.
Compares whether the JSP Bean specified by the name attribute of the tag is equal to the value attribute of the tag (the property attribute does not appear) or compares whether the property attribute value of the JSP Bean specified by the name attribute of the tag is equal to the value attribute of the tag The values are equal.
Compares whether the parameter value specified by the parameter attribute of the tag (in the request) is equal to the value attribute of the tag.
4. logic:notEqual
The meaning of this tag is opposite to logic:equal, and its usage is similar, which is omitted.
5. logic:forward
This tag is used to implement page guidance and find the global forward of configuration files. Global redirection in struts-config.xml file
eg. <logic:forward name="redirect"/>
6. logic:greaterEqual
Is the greater than or equal comparison operator.
eg. When a student's score is greater than or equal to 60, output "pass":
<logic:greaterEqual name="student" property="scores" value="60">
pass
</logic:greaterEqual>
7. logic:greaterThan
This is the greater than comparison operator, and its usage is the same as logic:greaterEqual;
8. logic:lessEqual
This is a less than or equal comparison operator, and its usage is the same as logic:greaterEqual;
9. logic:lessThan
This is a less than comparison operator, and its usage is the same as logic:greaterEqual;
10. logic:match
This tag compares objects for equality;
The logic:match tag is used to handle substring matching problems.
If the specified value matches the tag, the contents of its tag body will be created. This tag is used in the following situations:
Checks whether the cookie with the specified name matches the value of this tag.
Checks whether the header with the specified name matches the value of this tag.
Checks whether the JSP Bean with the specified name matches the value of the tag or checks whether the property attribute value in the JSP Bean with the specified name matches the value of the tag.
Checks whether the parameter value of the specified name in the request matches the value of the tag.
The following code illustrates typical usage of the logic:match tag:
eg0.
12. logic:messagePresent
This tag is used to determine whether the ActionMessages/ActionErrors object exists;
The logic:messagesPresent tag is used in the following situations:
There is an ActionMessages object in the request scope, and the property attribute of the label corresponds to the property in ActionMessages.
There is an ActionErrors object in the request scope, and the property attribute of the label corresponds to the property in ActionErrors.
There is a String object, convert (construct) it into ActionMessage and then add it to ActionMessages.
There is a String Array object, convert each String in the array into an ActionMessage, and then add it to ActionMessages.
When the value of the message attribute of the tag is true, Globals.MESSAGE_KEY will be used as the key to search for Message in the request scope. In other cases, the value of name will be used as the key to search. If name does not appear, the default value is Globals.ERROR_KEY.
The following code illustrates typical usage of the logic:messagesPresent tag:
eg1.
14. logic: present
This tag is used to determine whether the parameters passed by the request object exist.
If the specified value appears, the tag will create the contents of its tag body. This tag is used in the following situations:
Checks whether a cookie with the specified name is present.
Checks whether a header with the specified name appears.
Checks whether the JSP Bean with the specified name appears or checks whether the property attribute in the JSP Bean with the specified name appears.
Check whether the parameter with the specified name in the request appears.
Checks whether the currently authenticated user is associated with the specified security role.
Checks whether the currently authenticated subject has the specified name.
eg1. When both the user object and its name attribute exist in the request, the corresponding string is output:
Let's see the difference between these two actions:
Forward is executed inside the servlet. The browser will not be aware of this action at all, and the original URL will not change. If the browser is reloaded, it will simply repeat the original request.
Redirect is divided into two steps: the first step is that the web application tells the browser the second URL, and then the browser sends a request to the second URL.
Redirect is slower than forward because the browser has to make a second request. Also note that the beans in the first request scope (request scope) are not visible to the second request.
After understanding the differences described above, you will know when to use the logic:forward tag and when to use the logic:redirect tag.
The logic:forward tag completes PageContext.forward() or HttpServletResponse.sendRedirect(). The choice is determined by the controller. The logic:redirect tag completes HttpServletResponse.sendRedirect().
When using the logic:redirect tag, we can construct the baseurl and query parameters just like using html:link. If you are interested, you can refer to the html:link tag.