Building JSP using the Expression Language
EL的基本语法与运算子 ${ EL表示式 }
El隐含对象
隐含对象名称è用途(等同于何方法)è范例
pageScopeè从page范围取得某属性è${pageScope.title}
requestScopeè从request范围取得某属性è${requestScope.title}
sessionScopeè从session范围取得某属性è${sessionScope.loginName}
applicationScopeè从application范围取得某属性è${applicationScope.profile}
pageContextè包含JSP网页信息的pageContext对象è${pageContext.request.requestURI}
paramèServletRequest.getParameter()方法è${param.productlId}
paramValuesèServletRequest.getParameterValues()方法è${paramValues.categories[0]} (数组)
headerèServlet.Request.getHeader()方法è${header[“User-Agent”]}
headerValuesèServlet.Request.getHeaders()方法è${headerValues[“Accept-Encoding”][0]}
cookieèServletRequest.getCookies()方法è${cookie.username}
initParamèServletContext.getInitParameter()方法è${initParam.logDirectory}
注意:只有pageContext的类型为java.servlet.ServletContext,其它隐含物件类型均为java.util.Map
如果未指定范围,JSP容器会依序从page,request,session与application范围寻找该属性。(由小至大范围寻找)
注意:使用EL除法运算时,如果除数为0(例如10 div 0),结果会传回Infinity(无限大)。
EL算术运算子: + , - , * , / 或 div , % 或 mod
EL比较运算子:< 或 lt , > 或 gt , <= 或 le , >= 或 ge , == 或 eq , != 或 ne
EL ?号表达式:${逻辑表达式?值1:值2}
EL通过编写一个类,把方法设置为public,static,进行tld设置,可以实现静态功能。
.(dot)的左边可以为隐含对象或者attribte。[]左边可以为,bean,map,list或者数组。