java框架006——表达式语言(Expression Language,EL)

一、EL的基本语法

EL的基本语法如下:

${expr}

其中,$为EL语法中的输出符号,expr 为EL有效表达式,它包含在一对括号内。
EL有效表达式可以包含文字、操作符、变量(对象引用)和函数调用等。

二、EL有效表达式支持的内容类型

在这里插入图片描述

三、EL有效表达式支持的操作符

在这里插入图片描述

四、EL支持的隐式对象

在这里插入图片描述

4.1、隐式对象

。注意:不要将上述隐式对象与 JSP 内置对象混淆,其中只有一个对象pageContext是它们所共有的。
。说明:尽管 JSP 和 EL 隐式对象中只有一个公共对象( pageContext ),但通过 EL 也可以访问其它 JSP 隐式对象。原因是 pageContext 拥有访问所有其它八个 JSP 隐式对象的功能。

五、.与 [ ] 运算符

。EL 提供了两种不同的存取器:点运算符( . )和方括号运算符( [] )。
。点运算符通常用于访问对象的属性。
。方括号运算符用来检索数组和集合的元素。

六、EL表达式实例

在这里插入图片描述
在这里插入图片描述

testEL.jsp文件
在这里插入图片描述
el.jsp文件

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<font color="red">EL 运算</font><br>
	Adult:${param.age>=18}<br>
	Empty:${empty param.age }<br><!-- 判断是否有这个属性false or true -->
	Empty:${empty param.age12 }<br>
	Age:${param.age>18?"成年人":"未成年"}<br>
	<br>

	<font color="red">EL pageContext操作</font><br>
	Request:${pageContext.request }<br>
	Response:${pageContext.response }<br>
	Session:${pageContext.session }<br>
	Application${pageContext.servletContext}<br>
	<br>
	RequestContextPath:${pageContext.request.contextPath }<br>
	Response:${pageContext.response }<br>
	SessionId:${pageContext.session.id }<br>
	ApplicationServerInfo${pageContext.servletContext.serverInfo}
	<br><br>
	
	
	<font color="red">EL cookie header initParam操作</font><br>
	Cookie-JSESSIONID:${cookie.JSESSIONID}<br>
	Cookie-JSESSIONID-Name:${cookie.JSESSIONID.name}<br>
	Cookie-JSESSIONID-Value:${cookie.JSESSIONID.value}<br>
	Header:${header["Accept-Language"]}<br>
	initParam:${initParam["name"]}<br><!-- 获取web.xml中context-param标签配置的相关值 -->
	<br>
	
	
	<font color="red">EL参数操作</font><br>
	Name:${param.name}<br>
	Number:${paramValues.number[0]}<br><!-- 去数组里面的第一个 -->
	<br>
	
	
	<font color="red">EL域对象操作</font><br>
	page:${pageScope.Attribute }<br><!-- pageScope获取不到,因为其作用域只在一个页面 -->
	request:${requestScope.Attribute }<br>
	session:${sessionScope.Attribute }<br>
	application${applicationScope.Attribute }<br>
	Attribute:${Attribute }<br><!-- 直接写Attribute,先到page找,再到request,session,application中一次查找,找到一个就停止 -->
	<br>
	
	
	<font color="red">EL自动类型转换</font><br>
	Age+12:${param["age"]+12}<br><br><!-- 使用.无法使用 -->
	
	
	<font color="red">EL语法</font><br>
	Name:${param.name}<br>
	Name:<%=request.getParameter("name") %><br>
	Age:${param["age"]}<br>
	Dot:${pageContext.session.servletContext.contextPath}<br>
</body>
</html>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值