el表达式

来源:互联网 发布:手机壳品牌知乎 编辑:程序博客网 时间:2024/05/29 02:31

1.EL 表达式概述
EL(Express Lanuage)表达式可以嵌入在jsp页面内部,减少jsp脚本的编写,EL 出现的目的是要替代jsp页面中脚本的编写。

2.EL从域中取出数据(EL最重要的作用)

jsp脚本:<%=request.getAttribute(name)%>EL表达式替代上面的脚本:${requestScope.name}

EL最主要的作用是获得四大域中的数据,格式${EL表达式}

EL获得pageContext域中的值:${pageScope.key};EL获得request域中的值:${requestScope.key};EL获得session域中的值:${sessionScope.key};EL获得application域中的值:${applicationScope.key};EL从四个域中获得某个值${key}; (重点)---同样是依次从pageContext域,request域,session域,application域中   获取属性,在某个域中获取后将不在向后寻找

3.EL的内置对象11个

pageScope,requestScope,sessionScope,applicationScope ---- 获取JSP中域中的数据param,paramValues   - 接收参数.相当于request.getParameter()  rrquest.getParameterValues()header,headerValues  - 获取请求头信息相当于request.getHeader(name)initParam               - 获取全局初始化参数相当于this.getServletContext().getInitParameter(name)cookie                  - WEB开发中cookie相当于request.getCookies()---cookie.getName()---cookie.getValue()pageContext         - WEB开发中的pageContext.

pageContext获得其他八大对象

${pageContext.request.contextPath}(重点)相当于
<%=pageContext.getRequest().getContextPath%> 这句代码不能实现
获得WEB应用的名称
4.EL执行表达式

例如:${1+1}${empty user}判断user是否为空${user==null?true:false}
原创粉丝点击