JSTL: FN

Source: Internet
Author: User
Introduction on jsp pages, we often encounter application requirements such as set length, character length, and character cutting. Before the 20 s, this requirement was one of the many programmers who were not satisfied with JSTL. Therefore, the functions tag is added in 20 to support the above requirements. Reference & lt; % @ t Introduction: on jsp pages, you often encounter application requirements such as set length, character length, and character truncation, in the past 2.0, such a requirement was one of the many programmers who were not satisfied with JSTL. To this end, the functions tag is added to section 2.0, which provides support for the above requirements. Reference using method <% @ taglib uri =" http://java.sun.com/jsp/jstl/functions "Prefix =" fn "%> Function Description: Function Description fn: contains (string, substring) if the string parameter contains the substring parameter, true fn: containsIgnoreCase (string, substring) is returned) returns true fn: endsWith (string, suffix) if the parameter string contains the substring (Case Insensitive). returns true fn: escapeXml (string) if the parameter string ends with suffix) convert XML (and HTML) with the corresponding XML character entity code and return fn: indexOf (string, substring) returns the position fn: join (array, separator) where the substring parameter appears for the first time in the string parameter. Rray concatenates a new string with the given delimiter separator and returns it. Fn: length (item) returns the number of elements contained in the parameter item. The parameter Item type is array, collection, or String. For the String type, the return value is the number of characters in the String. Fn: replace (string, before, after) returns a String object. Replace all the places where the before parameter exists in the parameter string with the after string, and return the replaced result fn: split (string, separator) to return an array, use the separator parameter as the delimiter to split the string parameter. Each part of the split is an element of the array fn: startsWith (string, prefix). If the string parameter starts with the prefix parameter, true fn is returned: substring (string, begin, end) returns the string part of the parameter, starting from the begin parameter to the end position of the parameter, including the fn: substringAfter (string, substring) character of the end position) returns the substring fn: substringBefore (string, substring) next to the substring. returns the substring fn: toLowerCase (string) before the substring) convert all characters of the string parameter to lowercase, and convert the returned fn: toUpperCase (string) to uppercase for all characters of the string parameter, and return fn: trim (string) remove the spaces at the beginning and end of the string parameter, and return the example $ {fn. substring (string, begin, end)} is a self-tested Code <% @ page contentType = "text/html; charset = gbk "%> <% @ taglib uri =" http://java.sun.com/jsp/jstl/core "Prefix =" c "%> <% @ taglib uri =" http://java.sun.com/jsp/jstl/functions "Prefix =" fn "%> This is a JSTL test.






**************************************** **************************************** * Jstl fn function collections use expressions to simplify Page code, this is very convenient for some standard methods, such as the getter/setter method of bean, request parameters, context, and data in session, however, in practical applications, we often need to call some methods of objects on the page. For example, when I need to call the length method of a string to obtain the length of a string, in the previous development process, we had to convert the object to the String class first, and then call its length method. Such code is cumbersome and error-prone. Therefore, JSTL has several built-in methods for string operations, which can be used directly in expressions, greatly simplifying the code and providing code readability. In JSTL expressions, a function is used in the format of $ {ns: methodName (args ....)} before using these functions, you must introduce the declaration of the standard function in JSP. <% @ taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions" %> below is the list of methods self-contained in JSTL AND ITS description function name Function Description Example fn: contains determines whether the string contains another string Fn: containsIgnoreCase: determines whether the string contains another string (case-insensitive) Fn: endsWith determines whether the string ends with another string Fn: escapeXml converts some characters into XML Representation, for example <字符应该转为< ${fn:escapexml(param:info)} fn:indexof 子字符串在母字符串中出现的位置 ${fn:indexof(name, "-")} fn:join 将数组中的数据联合成一个新字符串,并使用指定字符格开 ${fn:join(array, ";")} fn:length 获取字符串的长度,或者数组的大小 ${fn:length(shoppingcart.products)} fn:replace 替换字符串中指定的字符 ${fn:replace(text, "-", "•")} fn:split 把字符串按照指定字符切分 ${fn:split(customernames, ";")} fn:startswith 判断字符串是否以某个子串开始 Fn: substring get substring $ {fn: substring (zip, 6,-1)} fn: substringAfter get substring starting from position of a character $ {fn: substringAfter (zip, "-")} fn: substringBefore obtain the substring from the start to the position of a character $ {fn: substringBefore (zip, "-")} fn: toLowerCase to lowercase $ {fn. toLowerCase (product. name)} fn: Convert toUpperCase to uppercase characters $ {fn. upperCase (product. name)} fn: trim the spaces before and after the string by trim $ {fn. trim (name)} function description fn: contains (string, substring) if the string parameter contains the substring parameter, true fn: contains is returned. IgnoreCase (string, substring) if the string parameter contains the substring parameter (case-insensitive), true fn: endsWith (string, suffix) is returned. If the string parameter ends with the suffix parameter, true fn is returned: escapeXml (string) converts XML (and HTML) with special meanings to the corresponding XML character entity code, and returns fn: indexOf (string, substring) returns the position fn: join (array, separator) where the substring parameter appears for the first time in the string parameter to concatenate a given array with the given delimiter separator, form a new string and return it. Fn: length (item) returns the number of elements contained in the parameter item. The parameter Item type is array, collection, or String. For the String type, the return value is the number of characters in the String. Fn: replace (string, before, after) returns a String object. Replace all places where the before parameter appears in the parameter string with the after string, and return the replaced result fn: split (string, separator) to return an array, use the separator parameter as the delimiter to split the string parameter. Each part of the split is an element of the array fn: startsWith (string, prefix). If the string parameter starts with the prefix parameter, true fn is returned: substring (string, begin, end) returns the string part of the parameter, starting from the begin parameter to the end position of the parameter, including the fn: substringAfter (string, substring) character of the end position) returns the substring fn: substringBefore (string, substring) next to the substring. returns the substring fn: toLowerCase (string) before the substring) convert all characters of the string parameter to lowercase, and convert the returned fn: toUpperCase (string) to uppercase for all characters of the string parameter, and return fn: trim (string)
Related Article

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.