在jsp中EL的表达式形似
${firstThing.secondThing}
其中firstThing可以是EL implicit object或者是一个attribute。
1. 如果firstThing和secondThing之间是一个dot,那么firstThing必须是个map或者bean。如果是map那么secondThing则是相应的key,如果是bean的话secondThing则应该有相应的getter和setter。
2. [] 类似于dot但是更为强大,可以在数组和list的情况下使用。
3. El会显示纯文本,包括HTML ,例如
<div>
<b> bold tag:</b><br/>
${pageBean.tag1}
<div>
如果${pageBean.tag1}为<b></b> tags makes things bold!那么客户端不会看到<b></b>标签,这里需要将<换成<,>换成>
4. EL中的implicit objects
它们和jsp的implicit objects有些不同。
pageScope, requestScope, sessionScope, applicationScope are maps of the scope attributes. 一个应用是为防止naming conflict。
param and paramValues are maps of request parameters.
从下面的例子可以看到${param.nam}同于${paramValues.name[0]}。${param.food}只会显示第一个数值。
<div>
<b> bold tag:</b><br/>
<form action=”TestBean.jsp”>
Name: <input type=”text” name=”name”>
ID#: <input type=”text” name=”empID”>
First food: <input type=”text” name=”food”>
Second food: <input type=”text” name=”food”>
<input type=”submit”>
</form>
Request param name is: ${param.name} <br>
Request param empID is: ${param.empID} <br>
Request param food is: ${param.food} <br>
First food request param: ${paramValues.food[0]} <br>
Second food request param: ${paramValues.food[1]} <br>
Request param name: ${paramValues.name[0]}
header,${header.host}同于<%= request.getHeader("host") %>。
cookie
<% Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++) {
if ((cookies[i].getName()).equals(“userName”)) {
out.println(cookies[i].getValue());
}
} %>
${ cookie.userName.value}
5. EL 的操作符
在逻辑上el 会将null视为false,算术上则视为0。
Arithmetic (5)
Addition: +
Subtraction: -
Multiplication: *
Division: / and div
Remainder: % and mod
Logical (3)
AND: && and and
OR: || and or
NOT: ! and not
Relational (6)
Equals: == and eq
Not equals: != and ne
Less than: < and lt
Greater than: > and gt
Less than or equal to: <= and le
Greater than or equal to: >= and ge