您的位置:首页 > Web前端 > JavaScript

Unit05: WEB项目的开发模式 、转发 和 Unit09: EL、JSTL

2017-02-22 23:26 573 查看
Unit05: WEB项目的开发模式 、转发 和 Unit09: EL、JSTL

<%@page pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>查询学生</title>
</head>
<body>
<!-- 2.JSTL标签 -->
<!-- 2.1 if标签 -->
<p>
<c:if test="${stu.sex=='M' }">男</c:if>
<c:if test="${stu.sex=='F' }">女</c:if>
</p>
<!-- 2.2 choose标签 -->
<p>
<c:choose>
<c:when test="${stu.sex=='M' }">男</c:when>
<c:otherwise>女</c:otherwise>
</c:choose>
</p>
<!-- 2.3 forEach标签 -->
<p>
<c:forEach items="${stu.interests }" var="i">
${i }
</c:forEach>
</p>

<!-- 1.EL表达式 -->
<!-- 1.1访问Bean属性 -->
<!-- request.getAttribute("stu").getName() -->
<p>姓名:${stu.name }</p>
<p>年龄:${stu.age }</p>
<!-- 等价于stu.sex -->
<p>性别:${stu["sex"] }</p>
<!-- request.getAttribute("stu")
.getCourse().getId() -->
<p>课程ID:${stu.course.id }</p>
<!--
EL表达式的取值范围:
1)EL默认从4个隐含对象中依次取值
page->request->session->application
2)默认依次取值的规则,其意义在于简化EL
表达式,在取值时可以不用写对象名.
3)若希望打破默认规则,明确从某对象中取值,
则需要在表达式前面增加对象名.
requestScope.stu.name
sessionScope.stu.name
-->
<p>兴趣:${requestScope.stu.interests }</p>
<!-- 1.2访问时可以直接运算 -->
<p>年龄+5:${stu.age+5 }</p>
<p>介于20-30间:${stu.age>20 && stu.age<30 }</p>
<p>是否为空:${empty stu.interests }</p>
<!-- 1.3直接获取请求参数 -->
<p>参数:${param.user }</p>
</body>
</html>


student.jsp
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: