JSTL标签库可以支持5类标签
<c:out>
属性:
value:输出信息,可以是EL表达式或常量
default:value为空时显示信息
escapeXml:为true则避开特殊的xml字符集
例如:显示用户姓名,如果空在显示"guest"
<c:out value="${user.username}" default="guest" />
例如:指定从session中获取username的值显示
<c:out value="${sessionScope.user.username}" />
<c:set>
属性:
value:要保存的信息,可以是E表达式或者常量
target:需要修改属性的变量名,一般为javabean的实例,如果指定了target属性,那么property属性也必须指定
property:需要修改的javabean属性
var:需要保存信息的变量
scope:保存信息的变量范围
例如:将test.testinfo的值保存到session的test2中,其中test是一个JavaBean的实例,testinfo是test对象的属性:
<c:set value="${test.testinfo}" var="test2" scope="session" />
例如:将对象cust.address的city属性值保存到city中
<c:set target="${cust.address}" property="city" value="${city}" />
<c:remove>
属性:
value:要删除的变量
scope:被删除变量的范围
例如:从session中删除test2
<c:remove var="test2" scope="session" />
<c:if>
属性:
test:需要评价的条件
var:要求保存条件结果的变量名
scope:保存条件结果的变量范围
例如,如果user.sex值为“1”,则显示“user is man.”
<c:if test="${user.sex=='1'}" >
user is man.
</c:if>
<c:choose>
用于多选择的情况
<c:choose>
<c:when test="${user.generous}">
user.generous is true
</c:when>
<c:when test="${user.stingy}">
user.stingy is true
</c:when>
<c:otherwise>
user.generous and user.stingy is false
</c:otherwise>
</c:choose>
<c:forEach>
属性:
item:进行循环的项目
begin:开始条件
end:结束条件
step:步长
var:代表当前项目的变量名
varStatus:显示循环状态的变量
<c:forEach item="${vectors}" var="vector" >
<c:out value="${vector}" />
</c:forEach>
<c:forEach begin="0" end="100" var"i" step="1" >
<c:out value="${i}" />
</c:forEach>
<c:forTokens>
将字符串“a:b:c:d”以“:”分开循环4次,token存放当前分割到的字符串
<c:forTokens items="a:b:c:d" delims=":" var="token" >
<c:out value=""${token} >
</c:forTokens>
浙公网安备 33010602011771号