JSP 核心标签

参考http://www.runoob.com/jsp/jsp-jstl.html

在jsp中如果 使用如下标签

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

需要导入jar包

<!-- JSTL -->
<dependency>
    	<groupId>javax.servlet</groupId>
    	<artifactId>jstl</artifactId>
    	<version>1.1.0</version>
    </dependency>
    
 
<!-- JSTL实现包 -->
<dependency>
	<groupId>org.apache.taglibs</groupId>
	<artifactId>taglibs-standard-impl</artifactId>
	<version>1.2.5</version>
</dependency>

第一步:在.jsp文件中引用核心标签库,添加如下代码,就可以使用c标签

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
``标签。 var='sensorType' 代表集合${sensorTypes}中的一个元素; items='${sensorTypes}' 后台传过来一个集合list varStatus="state" 代表循环状态的变量名称,循环次数从0开始累加
<select class="sel_style" id="sensorTypeId" name="sensorType.id">
	<c:forEach var='sensorType' items='${sensorTypes}' varStatus="state">
	
	    <c:if test="${state.index%4==0}">
			<table class="print" id="printArea">
		</c:if>
		
		<c:if test="${sensor.sensorType.id==sensorType.id}">
			<option value='${sensorType.id}' selected="selected">${sensorType.name}</option>
		</c:if>
		<c:if test="${sensor.sensorType.id!=sensorType.id}">
			<option value='${sensorType.id}'>${sensorType.name}</option>
		</c:if>
	</c:forEach>
</select>
``标签。 该标签只有if条件,没有else条件 条件放在test中,其中${collectLine.isValid}是后台通过model传过来的变量,取值为0或1 ``` 是 否 是 否 ```

<c:choose> <c:when> <c:otherwise>标签

<!--
1.<c:when> <c:otherwise>标签放在<:choose>标签中
2.<c:when>标签 相当于if
3.<c:otherwise>标签 相当于else-->
<select name="isValid" id="isValid" class="form-control">
	<c:choose>
		<c:when test="${collectLine.isValid==1}"> 
				<option value=1 selected="selected">是</option>
				<option value=0>否</option>
		</c:when>
		<c:otherwise>  
				<option value=1>是</option>
				<option value=0 selected="selected">否</option>
		</c:otherwise>
	</c:choose>	 
</select>
posted on 2017-03-15 18:00  dreamstar  阅读(73)  评论(0编辑  收藏  举报