学习大数据——EL使用介绍

EL全称:Expression Language.表达式语言

作用:主要用来输出域对象中的属性值

EL表达式的查询规则
 先从page域中开始查找,找到后直接返回,不再向其他域中查找,如果找不到再去request域中查找,以此类推…
 如果在application域中仍找不到则返回空串
EL给我们提供了四个Scope对象,用来精确获取指定域中的属性值
 pageScope
  获取page域中的属性值
 requestScope
  获取request域中的属性值
 sessionScope
  获取session域中的属性值
 applicationScope
  获取application域中的属性值
 
 pageContext既是JSP的隐含对象又是EL的隐含对象,可以利用pageContext后去其他几个在EL中没有的JSP隐含对象

	 <%
	 	Date date = new Date();
	 	//将当前时间放到page页面
	  	pageContext.setAttribute("time", date+"-");
	 	request.setAttribute("time", date+"--");
	 	session.setAttribute("time", date+"---");
	 	application.setAttribute("time", date+"----");
	 	//创建Employee对象
	 	Employee employee = new Employee(1,"张三",new Department(1001,"开发部"));
	 	//将employee对象放到page域中
	 	pageContext.setAttribute("star", employee);
	 %>
	 通过JSP表达式属性当前时间:<%=date %><br>
	 通过EL表达式精确获page取时间:${time }<br>
	 通过EL表达式精确获取request时间:${requestScope.time }<br>
	 通过EL表达式精确获取session时间:${sessionScope.time }<br>
	 通过EL表达式精确获取application时间:${applicationScope.time }<br>
	 通过EL表达式输出Employee对象的lastName:${pageScope.star.lastName }<br>
	 通过EL表达式输出Employee对象的朋友:${pageScope.star.outName }<br>
	 通过EL表达式输出Employee对象的部门的名字:${pageScope.star.dept.name }<br>
	通过JSP表达式输出项目的虚拟路径:<%=request.getContextPath() %> <br>
	 通过EL表达式获取项目的虚拟路径:${pageContext.request.contextPath }
发布了37 篇原创文章 · 获赞 7 · 访问量 700

猜你喜欢

转载自blog.csdn.net/qq_40394792/article/details/104186043
今日推荐