EL(Expressin Language)表达式
可以代替jsp页面中的java代码
1)语法
${requestScope.student}
域对象
2)el语句不显示(配置不完整,系统忽略了EL表达式)
解决方案
1.
<%@ page isELIgnored="false" %>
2.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
</web-app>
3).和[]的区别
====.操作符===
${requestScope.student}
=======[]操作符======<br>
<%--单引号,双引号都可以--%>
${requestScope["student"]["address"]}
[]可以获取数组,变量,特殊符号
4)获取map属性
Map<String,Object> map = new HashMap<>();
map.put("cn","中国");
map.put("us","美国");
req.setAttribute("map",map);
req.getRequestDispatcher("elmap.jsp").forward(req,resp);
${requestScope.map.cn}
${requestScope.map["us"]}
5)关系逻辑运算符
${2>1}
${!true}
${5+6}
6)empty运算符
${empty requestScope["my-name"]}
7)隐式对象
JSP EL隐含对象
JSP EL支持下表列出的隐含对象:
隐含对象 | 描述 |
---|---|
pageScope | page 作用域 |
requestScope | request 作用域 |
sessionScope | session 作用域 |
applicationScope | application 作用域 |
param | Request 对象的参数,字符串 |
paramValues | Request对象的参数,字符串集合 |
header | HTTP 信息头,字符串 |
headerValues | HTTP 信息头,字符串集合 |
initParam | 上下文初始化参数 |
cookie | Cookie值 |
pageContext | 当前页面的pageContext |
您可以在表达式中使用这些对象,就像使用变量一样。接下来会给出几个例子来更好的理解这个概念。
${pageContext.request}-----》${pageContext.getRequest}
<%--级联--%>
${pageContext.request.serverPort}