实训第七天

来源:互联网 发布:javascript获取日期 编辑:程序博客网 时间:2024/04/30 09:29

前日回顾:

jsp实际上就是servlet;include(动态/静态)引入方法;注释、声明、java 脚本段等脚本语句;解决中文参数乱码的三个方法;用servlet+jsp+jquery 实现简单相册;

今日内容:

EL(Expression Language) 表达式:

EL 表达式 $ 与 { 之间不能有空格;

JSP EL 操作的内容:1 . 常量; 2 . 运算; 3 . 变量; 4 . 隐私对象;

1 . 常量

a . 布尔型:${true };  b . 整型:${10 };  c . 浮点型:${10.5 }; d . 字符串型:${"yangcheng" } 原样显示;e . 空类型:${null }什么与不显示;${true }; 如果是传过来的对象为 null,会显示null;

2 . 运算

a . EL 算术运算符:+,-,*,/,或 div、% 或 mod; 

b . EL 关系运算符:== 或 eq、!= 或 ne、< 或 lt、> 或 le、>= 或 ge; 

c . EL 逻辑运算符:&& 或 and、 || 或 or、 ! 或 not;

d . empty (单目) 运算符:用来判断值是否为 null 或空;为空时返回 true;否则返回 false;

ps: ${param.password1 == param.password2 } 是正确的写法;

<!-- $后面不能有空格 --><hr>${1+3 }<hr>${empty "" } ${empty null } ${empty "null" }<hr><%User user = new User();pageContext.setAttribute("user", user);List<User> userlist = new ArrayList<User>();userlist.add(new User());pageContext.setAttribute("userlist", userlist);%>${empty userlist }

3 . 变量

a . 依次从 page,request,session, application 域中查找:${变量名 };

b . 在制定域中查找

Ⅰ . pageContext 域:${pageScope.变量名 };

Ⅱ . requestContext 域:${requestScope.变量名 };

JSTL(JSP Standard Tag Library)--JSP 标准标签库

主要常用标签库:core

导入 core 标签库:<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

判断标签:

<c:if >: test 属性就是条件<c:if test ="${empty requestScope.fourth }"><h2> 没有fourth 的属性值</h2>

<c:choose>:<c:when> == if;

<c:if test="${1==2 }">222222</c:if><c:if test="${1==1 }">wwwwwwwwww2</c:if>

<%int a = (int)(Math.random() * 10);pageContext.setAttribute("a", a);%><c:choose><c:when test="${a==1 }">产生的随机数是1</c:when><c:when test="${a==2 }">产生的随机数是2</c:when><c:when test="${a==3 }">产生的随机数是3</c:when><c:otherwise>${a }</c:otherwise></c:choose>

原创粉丝点击