<%@page import="cn.hncu.domain.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<H2>EL表达式的运算符</H2>
<%
User u = new User();
u.setId("U001");
u.setName("Tom");
u.setPwd("1234");
u.setAge(24);
//把数据放到容器中
request.setAttribute("user", u);
%>
<p>可以使用算术运算符: + - * / % </p>
${user.age+20}
<pre>可以使用比较运算符: == != < > <= >= </pre>
${user.name=='Tom' && user.age>30 }
<p> 条件运算符 </p>
${ user.age>25 ? 'old' : "young" }
<p>判断是否为空的运算符: empty </p>
${empty user } ---如果user为null(根本就没有这样的属性) 或 空字符串 ,都是返回true <br/>
${!empty user }
</body>
</html>
--------------------------------------------------
<%@page import="cn.hncu.domain.User"%><!--这里记得是要导包 -->
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<H2>EL表达式的运算符</H2>
<%
User u = new User();
u.setId("U001");
u.setName("Tom");
u.setPwd("1234");
u.setAge(24);
//把数据放到容器中
request.setAttribute("user", u);
pageContext.setAttribute("a", "page_aaa");
session.setAttribute("a", "sess_aaa");
application.setAttribute("a", "app_aaa");
%>
<!-- 从指定容器读取数据,效率更高 -->
${requestScope.user.name}<br/>
${pageScope.a}<br/>
${sessionScope.a}<br/>
${applicationScope.a}<br/>
${a}
<br/><br/>
${header} <br/> ---是一个List< Map<key,value> >
${header.host } <br/>
${header.cookie} <br/>
${cookie.JSESSIONID.value }<br/>
<br/><br/>
${param} <br/>
${param.name }, ${param.age } <br/>
${paramValues} <br/> ---用于读取类似 兴趣爱好 这种参数 的值 (字符串数组) <br/>
${paramValues.name[0]}
${initParam} <br/>
${pageContext.request.contextPath}<br/><!--输出的项目的路径 -->
<%=request.getContextPath() %>
</body>
</html>