ArticleDirectory
- 4.1 El Operator
- 4.2 [] and. Two ways to access attributes or elements
- 4.3 list and map
- 4. Access static variables
1. Use servlet2.4/jsp2.0
1. confirm that the Web iner supports serverlet2.4, and copy jstl. jar and standard. Jar (see meta-INF for details) that support jstl 1.1 to Web-INF/lib.
2. In web. XML, change the root node
<Web-app version = "2.4" xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee
Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd>
3. In JSP, the introduction of core and FTM taglib is changed
<% @ Taglib prefix = "C" uri = "http://java.sun.com/jsp/jstl/core" %>
<% @ Taglib prefix = "FMT" uri = "http://java.sun.com/jsp/jstl/fmt" %>
2. Use El directly in HTML instead of <C: Out value = "">
Using the EL of jsp2.0, writing $ {book} directly in HTML instead of <C: Out value = "$ {book}"> can be very concise and comparable to velocity, freemarker interface.
3. Added function labels
The most useful one in the function label is to obtain the list and map size. There are also some stringutils and collection functions.
In jstl, it is really depressing not to call any methods except getxxx !!
<% @ Taglib prefix = "FN" uri = "http://java.sun.com/jsp/jstl/functions" %>
$ {Fn: length (mylist )}
4. Other El knowledge point 4.1 El Operators
In addition to the most basic arithmetic operators, logical operators, and comparison operators, there is also an empty operator used to determine whether the variable is null or list, and whether the map size is zero.
<C: If test = "$ {not empty mylist}">
El operators are available in two versions: Text and symbols, such as | and or,> = and GE. This is applicable when text or symbols are unavailable.
4.2 [] and. Two ways to access attributes or elements
$ {Book. name} is equivalent to $ {book ["name.
$ {Book ["name"]} is mainly used when the "name" string is a variable or the string contains the "." character.
For example, $ {mymap [order. Status]} is an important method for accessing map elements.
4.3 list and map
Orderlist [0] returns the first element.
Traverse map with key and Value
<C: foreach Var = "entry" items = "$ {mymap}">
<Option value = "$ {entry. Key}" >$ {entry. Value} </option> </C: foreach>
4. Access static variables
El itself does not support access to static variables, the work und is to write a tag, the static variables of a class is reflected into a map, such as http://www.javaranch.com/journal/200601/Journal200601.jsp#a3
However, using map will lose the significance of static variable compilation security. Therefore, we recommend that you use common JSP in this case. For details, see showorder. jsp.