您的位置:首页 > Web前端 > JavaScript

jsp中c标签的c:if和c:choose判断

2017-05-15 13:34 387 查看
1、

<c:if><c:if/>


相当于java中的:

if(true){

}


1.1 用法

—引入c标签包:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


—body中写入判断:

<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
<p>我的工资为: <c:out value="${salary}"/><p>
</c:if>


—属性说明:

test:条件(${}中为条件)。
var:用于存储条件结果的变量。
scope:var属性的作用域(可省略,默认值为page)。


2、

<c:choose>
<c:when test="<boolean>"/>
...
</c:when>
<c:when test="<boolean>"/>
...
</c:when>
...
...
<c:otherwise>
...
</c:otherwise>
</c:choose>


相当于java中的:

if(){
...
}else if(){
...
}else{
...
}


2.1 用法

—同样需要引入c标签包:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


—body中判断

<c:set var="salary" scope="session" value="${2000*2}"/>
<p>你的工资为 : <c:out value="${salary}"/></p>
<c:choose>
<c:when test="${salary <= 0}">
太惨了。
</c:when>
<c:when test="${salary > 1000}">
不错的薪水,还能生活。
</c:when>
<c:otherwise>
什么都没有。
</c:otherwise>
</c:choose>


属性说明:

<c:choose>标签没有属性
<c:when>标签只有一个属性:
test:意义同<c:if>标签属性
<c:otherwise>标签没有属性
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jsp 标签