Struts labels and jstl labels are exchanged, and struts labels jstl
Recently, a large number of struts labels were used in modern code when struts was switched to spring mvc, and common struts labels were summarized, first introduce <% @ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>1. logic: empty
Logic: the empty label is used to determine whether it is null. If it is null, the content embedded in the label body will be processed. This label is used in the following scenarios:
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 demonstrates the logic: empty tag to determine whether the set persons is empty:
<Logic: empty name = "listForm" property = "persons">
<Div> the set persons is empty! </Div>
</Logic: empty> you can replace <c: if> with <c: if test = "$ {listForm. persons = ''| listForm. persons = null} "> <div> the set persons is empty! </Div> </c: if><C: if> label attributes and descriptions
Attribute |
Description |
Test |
Conditions to be determined |
Var |
Name of the variable that saves the true or false judgment result. This variable is optional for later work) |
Scope |
The scope of the variable. If not specified, the default value is the variable stored in the page range (optional) |
2. logic: notEmptyOpposite to logic: empty, it is used to judge non-null values: <c: if test = "$ {listForm. persons! = ''& ListForm. persons! = Null} "> <div> the set persons is not empty! </Div> </c: if>
3. Comparison OperatorLogic: equal (=)
Logic: notEqual (! =)
Logic: greaterEqual (> =)
Logic: lessEqual (<=)
Logic: graterThan (>)
Logic: lessThan (<) can also be replaced using <c: if>.
4. logic: iterator
Lists the collection values (List, ArrayList, HashMap, and so on ).
Logic: the iterate label is used to iterate the set. You can specify the set for which the label is to be stacked as follows:
Use a runtime expression. The value of this expression is a set.
Reference a JSP Bean using the name attribute. the JSP Bean itself is a set.
Reference a JSP Bean with the name attribute. One attribute of this JSP Bean is a set. In this case, you can use property to specify this set. <Logic: iterate id = "emp" name = "empList">
<Bean: write name = "emp" property = "name"/> <br>
</Logic: iterate> you can replace <c: forEach> with <c: forEach items = "$ {empList}" var = "emp"> <c: out value = "$ {emp. name} "/> </c: forEach> if you need to obtain the index of the time span, you can set the varStatus attribute of <c: forEach>, through $ {status. index}: <c: forEach items = "$ {empList}" var = "emp" varStatus = "status"> <c: if test = "$ {status. index = 0} "> <c: out value =" $ {emp. name} "/> </c: if> </c: forEach> of course, we can also get the length of the set, at this time, we need to introduce <% @ taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions" %> through $ {fn: length (empList )} to obtain the length of a set. The following describes some labels used: <c: out> label attributes and descriptions.
Attribute |
Description |
Value |
Data output to the page, which can be EL expressions or constants (required) |
Default |
Data displayed when value is null (optional) |
EscapeXml |
When set to true, special characters such as "& lt;, & gt;, & amp;" are automatically replaced (optional, default value: true) |
<C: forEach> label attributes and descriptions
Attribute |
Description |
Items |
Set of loops (optional) |
Begin |
Start condition (optional) |
End |
End condition (optional) |
Step |
The cycle step. The default value is 1 (optional) |
Var |
Variable name of the object for loop. If the items attribute exists, it indicates the variable name of the object in the Loop set (optional) |
VarStatus |
Variable showing the loop status (optional) |
Functions tag Library
The Functions tag library has 16 Functions in two categories. Length function: fn: length string processing function: fn: contains, fn: containsIgnoreCase, fn: endsWith, fn: escapeXml, fn: indexOf, fn: join, fn: replace, fn: split, fn: startsWith, fn: substring, fn: substringAfter, fn: substringBefore, fn: toLowerCase, fn: toUpperCase, fn: trim
5. <bean: message key = "">For foreground International jstl label Library also provides the international label, need to introduce: <% @ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>
I18N formatting tag LibraryWhen you see I18N, you should think of the knowledge "Internationalization". The I18N formatting tag library is used for internationalization on the JSP page. There are a total of 12 tags in the tag library, which are divided into two categories: international core tags: <fmt: setLocale>, <fmt: bundle>, <fmt: setBundle>, <fmt: message>, <fmt: param>, and <fmt: requestEncoding>. Format tags: <fmt: timeZone>, <fmt: setTimeZone>, <fmt: formatNumber>, <fmt: parseNumber>, <fmt: formatDate>, <fmt: parseDate> for time reasons, we will share it here for the time being. I hope you can correct me more. Thank you! Note: