jsp el的使用规则

在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>标签,这里需要将<换成&lt;,>换成&gt;

 

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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值