天天看點

jsp頁面常用邏輯标簽與方法2.判斷标簽

1.循環标簽

<c:forEach items="${page.rows}" var="row" varStatus="status">
   ...
</c:forEach>
           

1.1.屬性

屬性 描述 是否必要 預設值
items 要被循環的資訊
begin 開始的元素(0=第一個元素,1=第二個元素)
end 最後一個元素(0=第一個元素,1=第二個元素) Last element
step 每一次疊代的步長 1
var 代表目前條目的變量名稱
varStatus 代表循環狀态的變量名稱

1.2.例子

<tbody>
	<c:forEach items="${page.rows}" var="row" varStatus="status">
		<tr>
			<td>${status.count}</td>
			<td><a href="${pageContext.request.contextPath }/commissionsalecount/${row.cosc_id}/showpage.action">${row.cosc_code}</a></td>
			<td>${row.cosc_count_start_month} - ${row.cosc_count_end_month}</td>
			<td><a href="#" target="_blank" rel="external nofollow"  data-toggle="modal" data-target="#customerShowDialog" οnclick= "showCustomer(${row.cosc_customer})">${row.cosc_customer_name}</a></td>
			<td>${row.cosc_product_hospital}</td>
			<td>${row.cosc_sale_sum_quantity}</td>
			<td>${row.cosc_sale_sum_month}</td>
			<td>${row.cosc_sale_sum_develop}</td>
			<td>${row.cosc_sale_sum_total}</td>
			<td>${row.cosc_sale_sales_names}</td>
			<td>${row.cosc_sale_creater_name}</td>
			<td>${row.cosc_create_date}</td>
		</tr>
	</c:forEach>
</tbody>
           

1.3.JSP頁面頭部引用

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

2.判斷标簽

<c:if test="<boolean>" var="<string>" scope="<string>">
   ...
</c:if>
           

2.1.屬性

屬性 描述 是否必要 預設值
test 條件
var 用于存儲條件結果的變量
scope var屬性的作用域 page

2.2.例子

<c:if test="${row.cocc_applicant_id == USER_SESSION.user_id || '進階管理者' == USER_SESSION.user_authority || '管理者' == USER_SESSION.user_authority}">
	<a href="${pageContext.request.contextPath }/commissioncashcount/${row.cocc_id}/editpage.action" class="btn btn-primary btn-xs">修改</a>
	<a href="#" class="btn btn-danger btn-xs" onclick="deleteCommissionCashCount(${row.cocc_id})">删除</a>
</c:if>
           

2.3.JSP頁面頭部引用

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

3.判斷指定變量是否包含某字元串的方法

fn:contains(指定變量,查找的字元串)
           

3.1.例子

<c:if test="${fn:contains(USER_SESSION.user_authority,'管理者')}">
	<a href="${pageContext.request.contextPath }/commissionsalecount/examine/${row.cosc_id}/verifyshowpage.action" class="btn btn-primary btn-xs">稽核</a>
</c:if>
           

3.2.JSP頁面頭部引用

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

4. 自定義i的循環

<c:forEach var="i" begin="1" end="10" step="1">
    ${i}
</c:forEach>