Struts label swap with JSTL label

Source: Internet
Author: User
Tags i18n

The recent struts switch to spring MVC found that a large number of struts tags were used in the code, summarizing the commonly used struts tags, first to introduce<%@ taglib prefix="C" uri="http://java.sun.com/jsp/jstl/core"%> 1.logic:empty
The logic:empty tag is used to determine if it is empty. If empty, the content embedded in the tag body is processed. This label is used for 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 logic:empty the label to determine whether the collection persons is empty:
<logic:empty name= "ListForm" property = "Persons" >
<div> set persons is empty!</div>
</logic:empty> can be replaced with <c:if> in Jstl: <c:if test= "${listform.persons = =" | | listform.persons = NULL} "&  Gt <div> set persons is empty!</div></c:if> <c:if> Tag Properties and descriptions
Property Describe
Test Conditions that need to be judged
Var A variable name that holds a true or false judgment result, which can be used for later work (optional)
Scope The scope of the variable, if not specified, defaults to the variable saved in the page range (optional)
2.logic:notemptyContrary to logic:empty, used to judge non-null: <c:if test= "${listform.persons! =" && listform.persons! = null} "> <div> collection P Ersons is not empty!</div></c:if> 3. Comparison charactersLogic:equal (=)
Logic:notequal (! =)
Logic:greaterequal (>=)
Logic:lessequal (<=)
Logic:graterthan (>)
Logic:lessthan (<) This category can also be used to replace <c:if> 4. Logic:iterator
Used to display a list of collection values (list, Arraylist,hashmap, and so on).
The logic:iterate tag is used to iterate over the collection, and you can use the following method to specify the collection to which you want to iterate:
Using a run-time expression, the value of this expression is a collection.
A JSP bean is referenced by the Name property, which is itself a collection.
Using the Name property to reference a JSP bean, a property of the JSP Bean is a collection that can be used together to specify the collection. <logic:iterate id= "emp" name= "Emplist" >
<bean:write name= "emp" property= "name"/><br>
</logic:iterate> can use <c:forEach> replace <c:foreach items= "${emplist}" var= "emp" > <c:out value= "${ Emp.name} "/></c:foreach> if you need to get the index of the traversal, you can set the <c:forEach> Varstatus property, which is obtained 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, when we need to introduce<%@ taglib prefix="FN" uri="http://java.sun.com/jsp/jstl/functions "%> get the collection length by ${fn:length (emplist)}The following is a description of some of the tags used:<c:out> Tag Properties and descriptions
Property Describe
Value Output to page data, either EL expression or constant (required)
Default Data that is displayed when value is null (optional)
EscapeXML When set to true, special characters are actively replaced, such as "&lt;,&gt;,&amp; (optional, true by default)

<c:forEach> Tag Properties and descriptions

Property Describe
Items A collection of loops (optional)
Begin Start condition (optional)
End End condition (optional)
Step Loop step, default = 1 (optional)
Var The name of the object variable that makes the loop, or, if there is an items property, the variable name of the object in the looping collection (optional)
Varstatus Variable that shows the loop state (optional)

Functions Tag Library

The Functions tag library is divided into two main categories, a total of 16 functions. Length function: Fn:length string handler function: Fn:contains, Fn:containsignorecase, Fn:endswith, Fn:escapexml, Fn:indexof, Fn:join, Fn:repla CE, Fn:split, Fn:startswith, fn:substring, Fn:substringafter, Fn:substringbefore, Fn:tolowercase, Fn:toUpperCase, Fn:trim 5.<bean:message key= "" >Used to do the foreground internationalization Jstl tag library also provides the internationalization tag, the use need to introduce:<%@ taglib prefix="FMT" uri=" Http://java.sun.com/jsp/jstl/fmt"%> i18n formatting Tag librarySee i18n should think of knowledge "internationalization", i18n formatting tag library is used in JSP page to do internationalization action. There are 12 tags in the tag library, which are divided into two categories: internationalization core Tags: <fmt:setLocale>, <fmt:bundle>, <fmt:setBundle>, <fmt: Message>, <fmt:param>, <fmt:requestEncoding>. Formatting tags: <fmt:timeZone>, <fmt:setTimeZone>, <fmt:formatNumber>, <fmt:parseNumber>, <fmt: Formatdate>, <fmt:parseDate> because of the time, and temporarily share here, I hope you can correct me, thank you! Additional notes: More about the use of Jstl tag library can be consulted: http://blog.csdn.net/h396071018/article/details/6663412

Struts tags are swapped with Jstl labels

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.