EL表达式作用:
向浏览器输出域对象中的变量或表达式计算结果。用来替换掉jsp表达式
语法:
- ${变量或者表达式}
案例:
<%--
Created by IntelliJ IDEA.
User: pc
Date: 17-4-13
Time: 下午5:04
To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.util.*" contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="org.omg.PortableServer.REQUEST_PROCESSING_POLICY_ID" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<%
String str = "小明";
pageContext.setAttribute("st",str);
pageContext.setAttribute("st1",str+"1", pageContext.PAGE_SCOPE);
pageContext.setAttribute("st2",str+"2",pageContext.REQUEST_SCOPE);
pageContext.setAttribute("st3",str+"3",pageContext.SESSION_SCOPE);
pageContext.setAttribute("st4",str+"4", pageContext.APPLICATION_SCOPE);
%>
EL表达式:${st}<br>
page_EL:${pageScope.st1}<br>
request_EL:${requestScope.st2}<br>
session_EL:${sessionScope.st3}<br>
application_EL:${applicationScope.st4}<br>
</body>
</html>
- 算数表达式 + - * /
例:${a+b} ${a/b}
${20+5}
${20*5}
- ${a>b} 比较运算 > < == != >= <=
${20>12}
- 逻辑运算 && || !
例:${a && b}
${true && true}
- 判空
null 或空字符串
<%
String str1 ="";
String str2 =null;
pageContext.setAttribute("str1",str1);
pageContext.setAttribute("str2",str2);
%>
判断为空:${str1==""}<br>
判断为null:${str2==null}<br>
判断为null或为 空:${str2==null||str1==""}<br>
判断为null或为 空:${empty str1}<br>
文集:JavaEE--学习笔记