常用域对象写法:
相当于,session/appliaction/…/.setAttribute(“key”,“10”)
code:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set scope="application" var="id" value="007"></c:set>
<c:set scope="session" var="name" value="邦德"></c:set>
<c:set scope="request" var="sex" value="男"></c:set>
<c:set scope="page" var="work" value="特工"></c:set>
编号:${applicationScope.id}<br/>
姓名:${sessionScope.name}<br/>
性别:${requestScope.sex}<br/>
职业:${pageScope.work}<br/>
<c:set scope="application" var="id" value="${applicationScope.id+1}"></c:set>
修改id:${id}<!-- 还可以结合EL使用 -->
常用标签
- if:
<c:if test="${applicationScope.id>7 }"><!--同样结合EL-->
<h1>你不是邦德</h1>
</c:if>
-choose
<c:choose>
<c:when test="${pageScope.money>10000 }">
<h2>高薪</h2>
</c:when>
<c:otherwise>
<h2>普通</h2>
</c:otherwise>
for循环:
<select>
<c:forEach var="i" begin="1" end="30" step="1"><!-- i在这里会自动存进当前页域对象,step表示每次遍历一次 -->
<option>第${pageScope.i}页</option>
</c:forEach>
</select>