JSTL外联标签库
首先得引入标签库
<%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core"%>
prefix:命名空间 用于区分与HTML原标签
uri:标签库的地址
常用prefix:
c:JSTL
s:struts2标签
fmt:格式化
C标签:通常和EL表达式连用
1.遍历标签
<c:forEach
items="需要遍历的集合[${deptList}]"
var="循环中使用的对象名[dept]"
varStatus="循环中使用的对象的当前状态"
step="步进"
begin="index开始的位置"
end="index开始的位置">
${dept.xxx}
</c:forEach>
输出标签:
<c:out value="值"></c:out>
判断标签
<c:if test="boolean值(通常使用EL表达式进行运算)[${x==1}]"></c:if>
创建对象标签
<c:setvar="str1" value="a:b:c:d"scope="session"></c:set>
var:变量名
value:给变量赋值
scope:此变量存放的作用域
取值:使用EL表达式${str1}
删除对象标签
<c:removevar="str1" scope="session"/>
var:需要删除的变量的引用名
scope:此变量存放的作用域
字符串分割标签
<c:forTokensitems="${str1}" delims=":" var="s">
items:需要分割的字符串
delims:字符
var:分割后遍历的变量
选择结构 类似于switch
<c:choose> ----
<c:when test="${x<5}">---->if
<c:out value="x<5"></c:out>
</c:when>
<c:when test="${x<10}">-->else if
<c:out value="x<10"></c:out>
</c:when>
<c:otherwise> ---->else
<c:out value="x>=10"></c:out>
</c:otherwise>
</c:choose>
跳转标签
<%reseponse.sendRedirect("get.jsp?mm1=ccccc")%>
<c:redirecturl="get.jsp">
【带到目标页面的参数】
【<c:paramname="mm1" value="ccccc"></c:param>】
</c:redirect>
格式化地址标签
<c:url var ="ul" value="get.jsp"></c:url>