EL与JSTL学习(一)EL技术

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()  request.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}                ——empty判断某个对象是否时null,是null返回true

${user==null?true:false}

原文地址:https://www.cnblogs.com/cxq1126/p/7896192.html