一般标签的使用
<c:set var="user" value="zhangsan" scope="session"/>
<c:set var="user" scope="session">
zhangsan
</c:set>
<c:set target="${user}" property="age" value="18"/>
<c:set target="${preference}" property="color">
${param.color}
</c:set>
<c:remove var="user" scope="session"/>
<c:catch var="exception">
<%
int i=5;
int j=0;
int k=i/j;
%>
</c:catch>
<c:out value="${exception}"/>
<c:out value="${exception.message}"/>
${exception.message}相当于exception.getMessage();
条件标签的使用
<c:if test="${user.visitCount == 1}">
execute...
</c:if>
<c:if test="${param.name == 'admin'}" var="result"/>
<c:out value="${result}"/>
<c:choose>、<c:when>、<c:otherwise>一起实现互斥条件的执行,类似于java中的if/else if/else语句
<c:choose>
<c:when test="${param.name == 'zhangsan'}">
${param.name} is manager!
</c:when>
<c:when test="${param.name == 'lisi'}">
${param.name} is salesman!
</c:when>
<c:otherwise>
${param.name} is employee!
</c:otherwise>
</c:choose>
迭代标签的使用
<c:forEach var="entry" items="${myHashMap}">
${entry.key}
${entry.value}
</c:forEach>
<c:forEach var="i" begin="100" end="110">
${i}
</c:forEach>
<c:forTokens items="zhangsan:lisi:wangwu" delims=":" var="name">
${name}
</c:forEach>
URL相关标签的使用
导入一个基于URL的资源,类似于<jsp:include>
<c:import>不仅可以在页面中导入同一个Web应用程序下的资源,还
可以导入不同Web应用程序下的资源,甚至是其他网站的资源。
当前页面同一个目录下:
<c:import url="a.jsp"/>
Web应用根路径下:
<c:import url="/b.jsp">
外部路径:
<c:import url="/hello.jsp" context="/ch17"/>
<c:import url="/hello.jsp" context="/ch17">
<c:param name="name" value="zhangsan"/>
</c:import>
定义一个链接
<c:url value="/abc/a.jsp"/ var="myUrl">
<c:url value="http://codefans.org/login" var="myUrl">
<c:param name="username" value="${param.username}"/>
<c:param name="password" value="${param.password}"/>
</c:url>
<a href='<c:out value="${myUrl}"/>'>Register</a>
重定向
<c:redirect url="a.jsp"/>
<c:redirect url="/max.jsp" context="/ch15">
<c:param name="num1" value="15"/>
<c:param name="num2" value="23"/>
</c:redirect>