//EL 的基本用法
类型 | 示例 | 对应的调用方法
javaBeans | ${user.username}* | user.getUsername()
| ${user["username"]} |
| ${user['username']} | sport[1]
数组 | ${sport[1]}* |
| ${sport['1']} |
| ${sport["1"]} |
List | ${address[2]}* | address.get(2)
| ${address['2']} |
| ${address["2"]} |
Map | ${phone["home"]} | phone.get("home")
| ${phone['home']} |
| ${phone.home}* |
//EL的内置对象(与JSP有区加别,只能在EL中使用,不能用在JSP中,名称不同但指同一个内容)
pageContext 对应JSP中当前页面上下文的对象
pageScope 对应JSP中page对象
requestScope 对应JSP中request对象
sessionScope 对应JSP中session对象
applicationScope 对应JSP中application对象
param 对应页面传值的对象
paramValues 对应页面传来一组值的对象
header 对应页面头信息的值对象
headerValues 对应页面头信息的数组对象
<%= session.getAttribute("phone")%>
等价于:
${sessionScope.phone}
cookie对应cookie对象的值
initParam对应设定的初始参数的值
//设定JSP不使用JSP EL
当前面页不使用
<%@page isELIgnored="true"%>
整个WEB应用不使用JSP EL
修改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>
----------------------------------------------------
pageContext.setAttribute("username",null)//false
pageContext.setAttribute("username","")//false
${empty username}//判断username是否为空
---------------------------------------------------
pageContext.setAttribute("username","janly")
request.setAttribute("username","janly")
session.setAttribute("username","janly")
application.setAttribute("username","janly")
${pageScope.username}
${requestScope.username}
${sessionScope.username}
${applicationScope.username}
${username}按作用域范围找查
-----------------------------------------
web.xml
<context-param>
<param-name>repeat</param-name>
<param-value>100</param-value>
</context-param>
${initParam.repeat}
${param.username}
---------------------------------
posted on 2009-11-29 22:02
junly 阅读(191)
评论(0) 编辑 收藏 所属分类:
jsp/servlet