JSP tag related issues; recommend everyone a domineering label Fn__js

Source: Internet
Author: User
Tags lowercase uppercase character
1. Background

Today dealt with a very aching need, service end of two values, in the JSP page to determine whether one of the values contains another value, using a number of label methods, not the syntax tag structure error is the data structure is not correct, and finally found two can complete the way the judgment contains, the following is a brief introduction: The way to Struts2 labels

<s:if test= "%{' ABCD '. indexof (' A ')}" >checked= "Checked" </s:if> jstl label Way

<c:if test= "${fn:contains (focustids,tu.id)}" >checked= "Checked" </c:if>

Say the above way so the problem came, struts label way quite disgusting, tried N times also did not try to come up with the service end of the variable put to the IndexOf function, the final jstl of the FN containing function perfectly solves the problem. 2.fn tags are described below

The page needs to introduce the following tags:

<% @taglib prefix= "s" uri= "/struts-tags"%>

<%@ taglibprefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>

<%@ taglibprefix= "FN" uri= "Http://java.sun.com/jsp/jstl/functions"%>

Below the popular science under the FN label related knowledge, from the network

Function Name Function Description Use example
Fn:contains determine if the string contains another string <c:if test= "${fn:contains (name, SearchString)}" >
Fn:containsignorecase determine if the string contains another string (case-insensitive) <c:if test= "${fn:containsignorecase (name, SearchString)}" >
Fn:endswith determines whether the string ends with a different string <c:if test= "${fn:endswith (filename,". txt ")}" >
Fn:escapexml convert some characters into XML representations, such as < characters should be converted to &lt; ${fn:escapexml (Param:info)}
Fn:indexof where the substring appears in the parent string ${fn:indexof (name, "-")}
Fn:join the data in the array into a new string and uses the specified character format to open ${fn:join (array, ";")}
Fn:length gets the length of the string, or the size of the array ${fn:length (shoppingcart.products)}
Fn:replace the character ${fn:replace specified in the replacement string (text, "-", "& #149;")}
Fn:split the string according to the specified word segmentation ${fn:split (customernames, ";")}
Fn:startswith determines whether a string starts with a substring <c:if test= "${fn:startswith (product.id," 100-")}" >
fn:substring Fetch substring ${fn:substring (zip, 6,-1)}
Fn:substringafter Gets the substring ${fn:substringafter (zip, "-") that starts at the location of a character.
Fn:substringbefore gets the substring from the start to the location of a character ${fn:substringbefore (Zip, "-")}
Fn:tolowercase to lowercase ${fn.tolowercase (product.name)}
Fn:touppercase is converted to uppercase character ${fn. Uppercase (Product.name)}
Fn:trim the space ${fn.trim (name)} before and after the string is removed

Function description

Fn:contains (string, substring) returns true if the parameter string contains a parameter substring
Fn:containsignorecase (string, substring) returns true if the parameter string contains the argument substring (ignore case)
Fn:endswith (string, suffix) returns true if the argument string ends with a parameter suffix
Fn:escapexml (String) converts XML (and HTML) with special meaning to the corresponding XML character entity code, and returns
Fn:indexof (string, substring) returns the position of the argument substring the first occurrence in the parameter string
Fn:join (array, separator) strings a given array of arrays with a given spacer separator, forming a new string and returning.
Fn:length (item) returns the number of elements contained in the parameter item. The parameter item type is an array, collection, or string. If it is a string type, the return value is the number of characters in string.
Fn:replace (String, before, after) returns a String object. Replaces all occurrences of the parameter before string in the parameter string with the argument after string and returns the result of the substitution
Fn:split (string, separator) returns an array with the argument separator as the separator string, and each part of the partition is an element of the array
Fn:startswith (string, prefix) returns true if the argument string begins with a parameter prefix
Fn:substring (string, begin, end) returns the string part of the argument string, starting with the argument start to the argument's position, including the character
Fn:substringafter (string, substring) returns the portion of the string that follows the argument substring in the parameter string
Fn:substringbefore (string, substring) returns the part of the argument substring in front of the parameter string
Fn:tolowercase (string) changes all characters in the parameter string to lowercase and returns them to the
Fn:touppercase (String) capitalizes all characters in the parameter string and returns them to
Fn:trim (String) removes the trailing space of the argument string and returns it
Introduction to JSP El
1, syntax structure ${expression} 2, [] and. Operator EL provides "." and "[]" two operators to access the data. When you want to access a property name that contains special characters, such as. or? etc. is not a sign of letters or numbers, be sure to use []. For example: ${user. My-name} should be changed to ${user["My-name"} if the value is to be dynamically fetched, it can be done with [], and "." Dynamic values cannot be achieved. For example: ${sessionscope.user[data] Data is a variable 3, the variable el access variable is a simple method, such as: ${username}. It means to remove a variable whose name is username in a range. Since we do not specify which range of username, it will be searched sequentially from page, Request, session, application range. If the way to find username, direct return, no longer continue to find, but if all the scope is not found, it will return null. The name of the attribute range in El Page pagescope Request requestscope session sessionscope Application Applicationscope


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.