在用spring mvc中,页面前端老用jstl,记录一下。
<c:choose>、<c:when>和<c:otherwise>在一起连用,可以实现Java语言中的if-else语句的功能。例如以下代码根据username请求参数的值来打印不同的结果:
<c:choose>
<c:when test="${empty param.username}">
Nnknown user.
</c:when>
<c:when test="${param.username=='Tom'}">
${param.username} is manager.
</c:when>
<c:otherwise>
${param.username} is employee.
</c:otherwise>
</c:choose>
以上标签等价于以下Java程序片段:
<%
String username=request.getParameter("username");
if(username==null){
//对应第一个<c:when>标签的主体
out.print("Nnknown user.");
}else if(username.equals("Tom")){
//对应第二个<c:when>标签的主体
out.print(username+" is manager.");
}else{
//对应<c:otherwise>标签的主体
out.print(username+" is employee.");
}
%>
<c:choose>、<c:when>和<c:otherwise>标签的使用必须符合以下语法规则:
<c:when>和<c:otherwise>不能单独使用,它们必须位于<c:choose>父标签中。
在<c:choose>标签中可以包含一个或多个<c:when>标签。
在<c:choose>标签中可以不包含<c:otherwise>标签。
在<c:choose>标签中如果同时包含<c:when>和<c:otherwise>标签,那么<c:otherwise>必须位于<c:when>标签之后。
更详细的查看(各种标签的使用):
http://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm
相关推荐
◎ JSTL的基本概念、安装与配置 ◎ JSTL的通用标记:<c:out>、<c:set>、<c:remove>和<c:catch>标记...◎ 条件处理标记:<c:if>、<c:choose>、<c:when>和<c:otherwise>标记 ◎ 循环标记:<c:forEach>和<c:forTokens>标记
choose,c:when,c:otherwise</li><br><br> <c:choose><br> <c:when test="${v1 gt v2}"><br> v1 大于 v2<br> </c:when><br> <c:otherwise><br> v1 小于 v2<br> </c:otherwise><br> </c:choose><br> <br><br> <c:...
<c:when test="${pageIndex eq pageNumber}"> <option value="${pageIndex}" selected="selected">${pageIndex}</option> </c:when> <c:otherwise> <option value="${pageIndex}">${pageIndex}</option> ...
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'queryStudent.jsp' starting page</...
用于复杂判断的 <c:choose>?、 <c:when>?、 <c:otherwise>?标签? 用于循环的 <c:forEach>?标签 用于分隔字符的 <c:forTokens>?标签? 用于包含页面的 <c:import> 用于得到 URL?地址的 <c:url>?标签? 用于页面...
1.关键字:JSTL标签、<c:choose>、<c:forEach>、<c:forTokens>、<c:if>、<c:import>、<c:otherwise>、<c:out>、<c:param>、<c:redirect>、<c:remove>、<c:url>、<c:when>、<c:set>、<c:catch>
EL表达式 (详解) EL表达式 1、EL简介 1)语法结构 ${expression} 2)[]与.... EL 提供.和[]两种运算符来存取数据。...=或ne、<或lt、>或gt、<=或le、>=或ge 3.逻辑运算符有三个:&&或and、||或or、!或not ...
13.3.6、<c:choose>、<c:when>、<c:otherwise>标签 13.3.7、<c:forEach>标签 13.3.8、<c:forTokens>标签 13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 ...
13.3.6、<c:choose>、<c:when>、<c:otherwise>标签 13.3.7、<c:forEach>标签 13.3.8、<c:forTokens>标签 13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 ...
13.3.6、<c:choose>、<c:when>、<c:otherwise>标签 13.3.7、<c:forEach>标签 13.3.8、<c:forTokens>标签 13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1...
13.3.6、<c:choose>、<c:when>、<c:otherwise>标签 13.3.7、<c:forEach>标签 13.3.8、<c:forTokens>标签 13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1...
13.3.6、<c:choose>、<c:when>、<c:otherwise>标签 13.3.7、<c:forEach>标签 13.3.8、<c:forTokens>标签 13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1...
13.3.6、<c:choose>、<c:when>、<c:otherwise>标签 13.3.7、<c:forEach>标签 13.3.8、<c:forTokens>标签 13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 ...
13.3.6、<c:choose>、<c:when>、<c:otherwise>标签 13.3.7、<c:forEach>标签 13.3.8、<c:forTokens>标签 13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1...
13.3.6、<c:choose>、<c:when>、<c:otherwise>标签 13.3.7、<c:forEach>标签 13.3.8、<c:forTokens>标签 13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 ...
2.流程控制标签:if、choose、when、otherwise 3.循环标签:forEach、forTokens 4.URL操作标签:import、url、redirect 使用标签时,一定要在jsp文件头加入以下代码: <%@taglib prefix="c" uri=...
7.3 动态SQL 动态 SQL 元素和使用 JSTL 或其他类似基于 XML 的文本...2 choose、when、otherwise元素 相当于结构:if -- else if -- else if -- else <choose> <when test = "条件1"> 语句1 </when> <when test = "条
查询出列表,也就是返回list, 在我们这个例子中也就是 List<User> , 这种方式返回数据,需要在User.xml 里面配置返回的类型 resultMap, 注意不是 resultType, 而这个resultMap 所对应的应该是我们自己配置的 ...
1.表达式控制标签:out、set、remove、catch 2.流程控制标签:if、choose、when、otherwise 3.循环标签:forEach、forTokens 4.URL操作标签:import、url、redirec