JSP Expression Language

操作符

The Arithmetic Operators

There are the expected operators here: +, -, *, /, %. You can also use the following for the / and % operators: div and mod. You can see examples of these being used in Listing 13.7:

<p>Now for some math:<br>
6 + 7 = ${6+7}<br>
8 x 9 = ${8*9}<br>
The Relational Operators

The relational operators are shown in Table 3.2.

Table 3.2 The Relational Operators

Symbol Version

Text Version

==

eq

!=

ne

<

lt

>

gt

>=

ge

<=

le


Notice that they all have a text version in addition to the more familiar symbol version. These are also used in Listing 13.7:

Here are some basic comparisons:

<p>
Is 1 less than 2? ${1<2} <br>
Does 5 equal 5? ${5==5} <br>
Is 6 greater than 7? ${6 gt 7}<br>
The Logical Operators

The logical operators are the same as the Java Programming Language, but they also have their textual equivalents within the EL. They are shown in Table 3.3.

Table 3.3 The Logical Operators

Symbol Version

Text Version

&&

and

||

or

!

not


The empty Operator

The empty operator allows you to test the following:

  • Object references to see if they are null.

  • Strings to see if they are empty.

  • Arrays to see if they are empty.

  • Lists to see if they are empty.

  • Maps to see if they are empty.

You use the operator in the following way:

empty variableName

If any of the above conditions are met, then the operator returns true.

Operator Precedence

The operator precedence works from the highest precedence through to the lowest precedence, and then left to right - In other words, the same as the Java programming language. As with any other programming language, you can affect this precedence with the use of parentheses ().

The operator precedence table as defined by the JSP 2.0 specification is shown below in Table 3.4:

Table 3.4 The Operator Precedence Table for the EL

[] .

()

-(unary) not ! empty

* / div % mod

+ - (binary)

<> <= >= lt gt le ge

== !- eq ne

&& and

|| or

一个新的EL操作符

?

例如

< select  name ="artist" >
< option  value ="1"  ${param.artist  ==  1 ? 'selected' : ''} >
Vesica Pisces
< option  value ="2"  ${param.artist  ==  2 ? 'selected' : ''} >
Cortical Control
< option  value ="3"  ${param.artist  ==  3 ? 'selected' : ''} >
Vida Vierra
</ select >  

The EL Implicit Objects

 

变量名称

说明

pageScope

一个包含所有page scope范围的变量集合 (a java.util.Map)

requestScope

一个包含所有request scope范围的变量集合 (a java.util.Map)

sessionScope

一个包含所有session scope范围的变量集合 (a java.util.Map)

applicationScope

一个包含所有application scope范围的变量集合 (a java.util.Map)

param

一个包含所有请求参数的集合 (a java.util.Map),通过每个参数对应一个String值的方式赋值

paramValues

一个包含所有请求参数的集合 (a java.util.Map),通过每个参数对应一个String数组的方式赋值

header

一个包含所有请求的头信息的集合, (a java.util.Map) ,通过每个头信息对应一个String值的方式赋值

headerValues

一个包含所有请求的头信息的集合 (a java.util.Map) ,通过每个头信息的值都保存在一个String数组的方式赋值

cookie

一个包含所有请求的 cookie集合 (a java.util.Map),   通过每一个cookie(javax.servlet.http.Cookie)对应一个cookie值的方式赋值

initParam

一个包含所有应用程序初始化参数的集合(a java.util.Map) ,通过每个参数分别对应一个String值的方式赋值

pageContext

一个javax.servlet.jsp.PageContext类的实例, 用来提供访问不同的请求数据

The Reserved Words

lt

ge

le

eq

and

true

ne

or

false

gt

not

null

instanceof

empty

div

mod

 

 

Expression Language Functions

函数

描述

fn:contains(string, substring)

如果参数string中包含参数substring,返回true

fn:containsIgnoreCase(string, substring)

如果参数string中包含参数substring(忽略大小写),返回true

fn:endsWith(string, suffix)

如果参数 string 以参数suffix结尾,返回true

fn:escapeXml(string)

将有特殊意义的XML (和HTML)转换为对应的XML character entity code,并返回

fn:indexOf(string, substring)

返回参数substring在参数string中第一次出现的位置

fn:join(array, separator)

将一个给定的数组array用给定的间隔符separator串在一起,组成一个新的字符串并返回。

fn:length(item)

返回参数item中包含元素的数量。参数Item类型是数组、collection或者String。如果是String类型,返回值是String中的字符数。

fn:replace(string, before, after)

返回一个String对象。用参数after字符串替换参数string中所有出现参数before字符串的地方,并返回替换后的结果

fn:split(string, separator)

返回一个数组,以参数separator 为分割符分割参数string,分割后的每一部分就是数组的一个元素

fn:startsWith(string, prefix)

如果参数string以参数prefix开头,返回true

fn:substring(string, begin, end)

返回参数string部分字符串, 从参数begin开始到参数end位置,包括end位置的字符

fn:substringAfter(string, substring)

返回参数substring在参数string中后面的那一部分字符串

fn:substringBefore(string, substring)

返回参数substring在参数string中前面的那一部分字符串

fn:toLowerCase(string)

将参数string所有的字符变为小写,并将其返回

fn:toUpperCase(string)

将参数string所有的字符变为大写,并将其返回

fn:trim(string)

去除参数string 首尾的空格,并将其返回

例如:

<% @ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"  %>
${fn:length(myCollection)}  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值