首页 > 学院 > 开发设计 > 正文

JSTL---core标签库

2019-11-08 02:05:56
字体:
来源:转载
供稿:网友

Core标签库

<%@ PRefix="c" uri="http://java.sun.com/jsp/jstl/core"%>一般用途的标签

1.<c:out>

      把表达式的结果打印到网页上

<c:out value="${param.name}"><c:out value="表达式" default=“默认值”><c:out value="表达式">默认值</c:out>//如果表达式为null,则输出默认值2.<c:set>

      2.1为string变量设定值

<c:set var="变量名" value="值" scope="默认page">      2.2为javaBean设定值

<c:set target="javabean的id" property="属性" value="值">      2.3为Map赋值

<c:set target="map  id" property="key" value="value">3<c:remove>

      删除特定范围内的命名变量

<c:remove var="变量" scope="">4<c:catch>

      捕获标签主体异常,保存在页面范围

<c:catch var="ex">//有可能出异常的代码</c:catch><c:out value="ex.message" default="no Exception">条件标签

1.<c:if>

<c:if test="表达式" var="表达式的值" scope=""><c:if test="${param.name='jack'}">只有test为true执行</c:if>2.<c:choose>,<c:when>,<c:otherwise>
<c:choose><c:when test=""></c:when><c:otherwise ></c:otherwise></c:choose>

迭代标签

1.<c:forEach>

<c:forEach var="name" items="集合" >${name}</c:forEach>1.1varStatus属性count:当前元素在集合中的序号,从1开始计数index:当前元素在集合中的索引,从0开始计数first:是不是第一个last:是不是最后一个
<c:forEach var="name" items="集合" varStatus="status">${name},${status.count},${status.index}</c:forEach>1.2 begin,end,step

<c:forEach var="name" items="集合" varStatus="status" begin="1" end="3" step="2">${name},${status.count},${status.index}</c:forEach>//开始索引,结束索引,步长2<c:forTokens>分割字符串
<c:forTokens  var="name" items="字符串" delims="分隔符,比如冒号">${name}</c:forTokens>//其他属性和forEach一样URL相关标签1.<c:import>
<c:import url="web资源url"/>不仅可以是本应用中的,也可以是其他web应用中的
<c:import url="xxx.jsp"/><c:import url="/xxx/aaa.jsp"/><c:import url="http://xxxx/aa/bbb.jsp"/>context属性包含同一个servlet容器下的其他web应用,不过crossContext==true
<c:import url="aaa.jsp" context="bbb"/>var属性把url内容输出到var中然后${xxxx}来输出2.<c:url> 按特定的规则重构url

<c:url value="原来url" var="新的url变量" scope="" /><c:param>子标签 name和value属性,就是url后面带的参数。会对特殊符号进行编码3.<c:redirect>重定向

<c:redirect url=""/>也有<c:param>子标签 context属性。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表