EL 表达式

来源:互联网 发布:微信能做淘宝客吗 编辑:程序博客网 时间:2024/05/29 05:54

 

  编辑本段简介1、语法结构

  ${expression}

  2、[ ]与.运算符

  EL 提供“.“和“[ ]“两种运算符来存取数据。

  当要存取的属性名称中包含一些特殊字符,如.或?等并非字母或数字的符号,就一定要使用“[ ]“。例如:

  ${ user. My-Name}应当改为${user["My-Name"]}

  如果要动态取值时,就可以用“[ ]“来做,而“.“无法做到动态取值。例如:

  ${sessionScope.user[data]}中data 是一个变量

  3、变量

  EL存取变量数据的方法很简单,例如:${username}。它的意思是取出某一范围中名称为username的变量。

  因为我们并没有指定哪一个范围的username,所以它会依序从Page、Request、Session、Application范围查找。

  假如途中找到username,就直接回传,不再继续找下去,但是假如全部的范围都没有找到时,就回传null。

  属性范围在EL中的名称

  Page PageScope

  Request RequestScope

  Session SessionScope

  Application ApplicationScope

  编辑本段有效表达式有效表达式可以包含文字、操作符、变量(对象引用)和函数调用。我们将分别了解这些有效表达式中的每一种:

  1、文字

  JSP 表达式语言定义可在表达式中使用的以下文字:

文字
文字的值
Boolean
true 和 false
Integer
与 Java 类似。可以包含任何正数或负数,例如 24、-45、567
Floating Point
与 Java 类似。可以包含任何正的或负的浮点数,例如 -1.8E-45、4.567
String
任何由单引号或双引号限定的字符串。对于单引号、双引号和反斜杠,使用反斜杠字符作为转义序列。必须注意,如果在字符串两端使用双引号,则单引号不需要转义。
Null
null

  2、操作符

  JSP 表达式语言提供以下操作符,其中大部分是 Java 中常用的操作符:

术语
定义
算术型
+、-(二元)、*、/、div、%、mod、-(一元)
逻辑型
and、&&、or、||、!、not
关系型
==、eq、!=、ne、、gt、<=、le、>=、ge。可以与其他值进行比较,或与布尔型、字符串型、整型或浮点型文字进行比较。
空操作符是前缀操作,可用于确定值是否为空。
条件型
A ?B :C。根据 A 赋值的结果来赋值 B 或 C。

  3、隐式对象

  JSP 表达式语言定义了一组隐式对象,其中许多对象在 JSP scriplet 和表达式中可用:

pageContext
JSP 页的上下文。它可以用于访问 JSP 隐式对象,如请求、响应、会话、输出、servletContext 等。例如,${pageContext.response} 为页面的响应对象赋值。

  此外,还提供几个隐式对象,允许对以下对象进行简易访问:

http://t.163.com/event/info/eventId/7429029921259703739http://t.163.com/event/info/eventId/2587404659841221713http://t.163.com/event/info/eventId/9132840545703390406http://t.163.com/event/info/eventId/-6942909235662401228http://t.163.com/event/info/eventId/1865043325387233679http://t.163.com/event/info/eventId/7784448359278091758http://t.163.com/event/info/eventId/8183611116857123467http://t.163.com/event/info/eventId/1727852956792153058http://t.163.com/event/info/eventId/4448909647116965061http://t.163.com/event/info/eventId/-5980810883031832489http://t.163.com/event/info/eventId/1952936733401929770http://t.163.com/event/info/eventId/-7922321845902806813http://t.163.com/event/info/eventId/-1413037330287003506http://t.163.com/event/info/eventId/-9035876669730275060http://t.163.com/event/info/eventId/5375358869605273690http://t.163.com/event/info/eventId/-1093817943957698022http://t.163.com/event/info/eventId/4423685836041806013http://t.163.com/event/info/eventId/6541320449691862239http://t.163.com/event/info/eventId/2358536422217464105http://t.163.com/event/info/eventId/-5356876296602325126http://t.163.com/event/info/eventId/4651189183937252834http://t.163.com/event/info/eventId/-2238868590001000881http://t.163.com/event/info/eventId/-7907920870940519859http://t.163.com/event/info/eventId/8321245964354785024http://t.163.com/event/info/eventId/2417725866395445216 http://t.163.com/event/info/eventId/296214758730922614http://t.163.com/event/info/eventId/691573143885919765http://t.163.com/event/info/eventId/4814913265437982535http://t.163.com/event/info/eventId/-2140691442100491709http://t.163.com/event/info/eventId/279815702729065697http://t.163.com/event/info/eventId/4495968764802730672http://t.163.com/event/info/eventId/1016928247563725798http://t.163.com/event/info/eventId/-5699475274983176866http://t.163.com/event/info/eventId/3291219197677224757http://t.163.com/event/info/eventId/-7700838406553495484http://t.163.com/event/info/eventId/126043288997375039http://t.163.com/event/info/eventId/7703802235518853186http://t.163.com/event/info/eventId/-1313160287337272548http://t.163.com/event/info/eventId/5935515069078705268 http://bbs.e23.cn/thread-175658812-1-1.htmlhttp://bbs.e23.cn/thread-175658816-1-1.htmlhttp://bbs.e23.cn/thread-175658818-1-1.htmlhttp://bbs.e23.cn/thread-175658822-1-1.htmlhttp://bbs.e23.cn/thread-175658824-1-1.htmlhttp://bbs.e23.cn/thread-175658827-1-1.htmlhttp://bbs.e23.cn/thread-175658829-1-1.htmlhttp://bbs.e23.cn/thread-175658831-1-1.htmlhttp://bbs.e23.cn/thread-175658832-1-1.htmlhttp://bbs.e23.cn/thread-175658838-1-1.htmlhttp://bbs.e23.cn/thread-175658841-1-1.htmlhttp://bbs.e23.cn/thread-175658844-1-1.htmlhttp://bbs.e23.cn/thread-175658854-1-1.htmlhttp://bbs.e23.cn/thread-175658856-1-1.htmlhttp://bbs.e23.cn/thread-175658858-1-1.htmlhttp://bbs.e23.cn/thread-175658859-1-1.htmlhttp://bbs.e23.cn/thread-175658863-1-1.htmlhttp://bbs.e23.cn/thread-175658866-1-1.htmlhttp://bbs.e23.cn/thread-175658870-1-1.htmlhttp://bbs.e23.cn/thread-175658874-1-1.htmlhttp://bbs.e23.cn/thread-175658877-1-1.htmlhttp://bbs.e23.cn/thread-175658879-1-1.htmlhttp://bbs.e23.cn/thread-175658883-1-1.htmlhttp://bbs.e23.cn/thread-175658884-1-1.htmlhttp://bbs.e23.cn/thread-175658887-1-1.htmlhttp://bbs.e23.cn/thread-175658888-1-1.htmlhttp://bbs.e23.cn/thread-175658890-1-1.htmlhttp://bbs.e23.cn/thread-175658894-1-1.html

http://bbs.e23.cn/thread-175658903-1-1.html

http://www.xyzc.cn/health/jsmr/20130828/489524.htmlhttp://www.xyzc.cn/health/jsmr/20130828/489507.html