您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
14_EL_empty运算符&隐式对象pageContext(empty与not empty)
发布时间:2022-09-11 18:36:42编辑:雪饮阅读()
主要就是了解下el的empty与not empty表达式以及隐式对象,这里pageContext就是隐式对象之一。一般的尤指pageContext.request。
empty对于空字符串(字符串长度为0)为true,空集合(如list集合)为true,null也会返回true。
not empty则正好相反。
实例如el3.jsp:
<%@ page import="java.util.*" %>
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2022/9/10
Time: 13:09
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
String str="kasumi";
String str2="";
String str3=" ";
String str4=null;
List list=new ArrayList();
list.add("list_v_1");
List list2=new ArrayList();
request.setAttribute("str",str);
request.setAttribute("str2",str2);
request.setAttribute("str3",str3);
request.setAttribute("str4",str4);
request.setAttribute("list",list);
request.setAttribute("list2",list2);
%>
<h1>el empty运算符</h1>
str is empty:${empty str}<br/>
str2 is empty:${empty str2}<br/>
str3 is empty:${empty str3}<br/>
str4 is empty:${empty str4}<br/>
list is empty:${empty list}<br/>
list2 is empty:${empty list2}<br/>
<h1>el not empty运算符</h1>
str is not empty:${not empty str}<br/>
str2 is not empty:${not empty str2}<br/>
str3 is not empty:${not empty str3}<br/>
str4 is not empty:${not empty str4}<br/>
list is not empty:${not empty list}<br/>
list2 is not empty:${not empty list2}<br/>
<h1>el 隐式对象</h1>
pageContext.request:${pageContext.request}<br/>
<!--隐式对象request的主要作用还就是用于获取虚拟目录居多(当前路径访问的伪项目根路径)-->
pageContext.request.contextPath:${pageContext.request.contextPath}<br/>
</body>
</html>
关键字词:EL,empty,运算符,&,隐式对象,pageContext,,not empty