Jstl details 2

Source: Internet
Author: User
Tags i18n
9.2.3 El expression Operator
There are many operators in the El expression that can help complete various required operations. In the previous example, "and" [] "are two of them. Table 9.1 is used to demonstrate all operators and their respective functions.
Table 9.1 El expression Operators
Functions and functions of Operators
. Access a bean attribute or map entry
[] Accessing an array or linked list element
() Grouping of child expressions, used to change the order of values
? : Condition Statement, for example: condition? Iftrue: iffalse
If the condition is true, the expression value is the former, and vice versa.
+ Mathematical operators, plus operations
-Mathematical operators: subtraction or inverse of a value
* Mathematical operators and multiplication operations
/Or Div mathematical operators, except operations
% Or mod mathematical operator, modulo operation (remainder)
= Or EQ logical operator to determine whether the two sides of the symbol are equal. If the two sides are equal, true is returned; otherwise, false is returned.
! = Or NE logical operator to determine whether the two ends of the symbol are not equal. If not equal, true is returned; otherwise, false is returned.
<Or lt logical operator to determine whether the left side of the symbol is smaller than the right side. If the value is smaller than the right side, true is returned. Otherwise, false is returned.
> Or the GT logical operator to determine whether the left side of the symbol is greater than the right side. If the value is greater than the right side, true is returned. Otherwise, false is returned.
<= Or Le logical operator to determine whether the left side of the symbol is less than or equal to the right side. If it is less than or equal to true, false is returned.
> = Or GE logical operator to determine whether the left side of the symbol is greater than or equal to the right side. If it is greater than or equal to true, false is returned.
& Or and logical operators, and operations. If both the left and right sides are true, true is returned. Otherwise, false is returned.
| Or logical operator, or operation assignment. True is returned if either side of the left or right is true. Otherwise, false is returned.
! Or not logical operator, not operator. If the return value is true, the return value is false. Otherwise, the return value is true.
Empty is used to judge an empty variable value: NULL, an empty string, an empty array, an empty map, and a collection set with no entries
Func (ARGs) calls the method. func is the method name, And ARGs is a parameter. It can be none, or there are one or more parameters. The parameters are separated by commas.

These operators are extremely useful. The following example shows how to use them:
Example 9.4: Examples of Operators
$ {Pagination. samplevalue + 12} <br> // display 12
$ {(Pagination. samplevalue + 12)/3} <br> // display 4.0
$ {(Pagination. samplevalue + 12)/3 = 4} <br> // display true
$ {(Pagination. samplevalue + 12)/3 >=5} <br> // display false
<Input type = "text" name = "sample1" value = "$ {pagination. samplevalue + 10}"> // text control with a display value of 10
As you can see, for these examples, the program designer does not need to manage their type conversion at all, and they have been processed inside the expression. With el expressions, JSP page programming becomes more flexible and easier.
9.2.3 introduction to the jstl tag Library
The following tag libraries are supported in jstl1.1: Core tag library, XML processing tag library, i18n formatting tag library, database access tag library, and functions tag library. The corresponding identifiers are shown in table 9.2:
Table 9.2 tag library identifier
Tag library URI prefix
Core http://java.sun.com/jsp/jstl/core C
XML processing http://java.sun.com/jsp/jstl/xml x
I18n formatting http://java.sun.com/jsp/jstl/fmt (FMT)
SQL database access http://java.sun.com/jsp/jstl/ SQL
Functions http://java.sun.com/jsp/jstl/functions FN

The following is an example of 9.5 simple use of the tag library.
Example 9.5: simple jstl tag library example
<% @ Page contenttype = "text/html; charset = UTF-8" %>
<% @ Taglib prefix = "C" uri = "http://java.sun.com/jsp/jstl/core" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Body>
<C: foreach Var = "I" begin = "1" End = "10" step = "1">
$ {I}
<Br/>
</C: foreach>
</Body>
</Html>
The JSP page in this example indicates that the core tag library is used, and its URI is "http://java.sun.com/jsp/jstl/core#, and its prefix is “c ". Then, the <C: foreach> label on the page uses the jstl label. The tag function is not described here for the time being. It just gives readers a simple concept to understand how to define and use the tag library.
9.3 jstl core tag Library
The core tag library, also known as the core tag Library, is used to encapsulate JSP pages. There are a total of 14 tags in the tag library, which are divided into four categories:
Q multi-purpose Core tags: <C: Out>, <C: Set>, <C: Remove>, and <C: Catch>.
Q condition control labels: <C: If>, <C: Choose>, <C: When>, and <C: otherwise>.
Q cycle control labels: <C: foreach> and <C: fortokens>.
Q url tags: <C: Import>, <C: URL>, <C: Redirect>, and <C: param>.
The following describes the usage, attributes, and simple examples of each tag.
9.3.1 <C: Out> label used for display
<C: Out> A tag is the most common tag used to display data in JSP. Its Attributes and descriptions are shown in table 9.3:
Table 9.3 <C: Out> label attributes and descriptions
Attribute description
The data that value outputs to the page. It can be an El expression or a constant (required)
Default data displayed when value is null (optional)
When escapexml is set to true, special characters are automatically replaced, such as "& lt;, & gt;, & amp;" (optional, the default value is true)

In jstl1.0, <C: Out> must be used to display data on the page. However, in jstl1.1, because the jsp2.0 specification already supports El expressions by default, expressions can be directly used on JSP pages. The following is an example.
<C: Out value = "$ {sessionscope. anyvalue}" default = "no value" escapexml = "false"/>
In this example, the parameter "anyvalue" is searched from the session and displayed on the page. If no value is found, "No value" is displayed ".

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.