JSP EL

1. EL 运算符
算术型: +, -, *, /(div), %(mod)
逻辑型: &&(and), ||(or), !(not)
关系型: ==(eq), !=(ne), >(gt), >=(ge), <(lt), <=(le)
条件型: a>b:c
空: empty
example:
${a/b} 等价于 ${a div b}
${empty string} 如果string 为null或"" 返回 true, 否则返回false
${empty object} 如果object 为null返回 true, 否则返回false
${{'a'>'b'} && (2<5)}


2. JSP EL 基本用法
[table]
| 类型 | example | 对应的java调用发方法|
| JavaBean | ${user.name}, ${user["name"] 或 ${user['name']} | user.getName |
| 数组 | ${users[1]}, ${users["1"]} 或 ${users['1']} | users[1] |
| List | ${users[1]}, ${users["1"]} 或 ${users['1']} | users.get(1) |
| Map | ${user.name}, ${user["name"] 或 ${user['name']} | user.get("name") |
[/table]


3. JSPEL 内置对象
[table]
|JSP EL内置对象| 对应的JSP内置对象 | 作用 |
| pageContext | pageContext | 页面上下文对象 |
| pageScope | page | 页面对象 |
| requestScope| request | 请求对象 |
| sessionScope | session | 会话对象 |
| applicationScope| application | 应用程序对象 |
| param|| 获取request中的参数 |
| paramValues|| 获取request中相同名字的参数组成的数组 |
| header|| |
| headerValues|| |
| cookie|| |
| initParam| | web.xml中context-param参数 |
[/table]
注意: EL 对象不能用于jsp 中, jsp 对象不能用于EL中
example:
${requestScope.username} 等价于 <%=request.getParameter("username")%>
${param.username} 等价于 <%=request.getParameter("username")%>
${username} 等价于 <%=request.getAttribute("username")%>
${paramValues.users[1]} 等价于
<% String[] users = request.getParameterValues("users"); out.println(users[1]);%>
${header.host} 输出header 中host的值
${cookie.userId.value} 输出cookies中userId的值
${initParam.repeat} 输出web.xml中context-param参数repeat的值

4.设定JSP不使用JSP EL
a.使用注释: \${username}
b.使用page指令: <%@page isELIgnored="true"%>
c.修改web.xml
<web-app>
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
</jsp-property-group>
</jsp-config>
</web-app>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值