Summary of JSTL Tag Libraries

JSTL tag library

Prepare:

The jar of jstl needs to be imported before use, and the jsp page needs to import the required tag library using the taglib command, which is generally used in combination with EL expressions

Import the core tag library as follows:      

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

Classification:

       The most commonly used is the core core tag library, the fmt format tag library

Common tags:

The <c:out> tag is used to display the result of an expression, similar to <%=%>, except that the <c:out> tag can directly access attributes through "."

<c:out value="${out}" default="1"/>

<c:set> is usually used to set the value of an expression

<c:set var="rootId" value="${rootDto.menuID}" />

<c:if> is used to judge, the result of the expression is true, enter the if tag, you can use empty, not empty, etc.

<c:if test="${empty roleList}">         
	<script>
		alert("Sorry, you do not have permission to operate this system!");
	    window.top.location = "../logout.screen";
	</script>
</c:if>



<c:if test="${not empty roleList && empty rootMenu}">
	 <c:out value="${a}"/>
</c:if>

<c:choose>  is equivalent to the syntax of if…else if ..else

<c:choose>    
  	<c:when test="${imageInfo.documentType eq 'P2P'}">
  	      <a href="javascript:showP2pImage('<c:out value="${imageInfo.url}"/>')"> </a>
  	 </c:when>
  	 <c:when test="${imageInfo.documentType eq 'camara'}">
  	      <a href="javascript:showCamarPhoto('<c:out value="${imageInfo.url}"/>')"> </a>
  	  </c:when>
  	  <c:otherwise>
<a href="javascript:showImage('<c:out value="${imageInfo.documentNo}"/>'</a> 	               
  	  </c:otherwise>
</c:choose>

<c:forEach> loops through tags, which can be used to traverse list, map, array, etc.

<c:forEach begin="0" end="${rowsCount}" var="in">
    <c:out value=${in}/>			
</c:forEach>
<c:forEach var="modMasInfoDTO" items="${modMasInfoDTO}">
    <c:out value= ${modMasInfoDTO.documentNo}/>		
</c:forEach>
expand:

The forEach tag also has an attribute: varStatus, which is used to specify the variable name that receives the "loop status", for example: <forEachvarStatus="vs".../>, then you can use the vs variable to get the loop status.

count: int type, the current number of elements to traverse;

index: int type, the subscript of the current element;

· first: boolean type, whether it is the first element;

· last: boolean type, whether it is the last element;

· current: Object type, representing the current item

<c:forEach var="item" items="${ns }" varStatus="vs">  
    <c:if test="${vs.first }">第一行:</c:if>  
    <c:if test="${vs.last }">最后一行:</c:if>  
    <c:out value="第${vs.count }行: "/>  
    <c:out value="[${vs.index }]: "/>  
    <c:out value="name: ${vs.current }"/><br/>  
</c:forEach>

<c:url> is used to dynamically generate a URL of type String

<script type="text/javascript" src="<c:url value="/script/common.js"/>"></script>

<c:redirect> This tag is used to redirect the request, if an exception occurs or the judgment condition is satisfied, jump to another page

<c:redirect url="http://127.0.0.1:8080/login.jsp">
	<c:param name="uname">lihui</c:param>
	<c:param name="password">11111</c:param>
</c:redirect>

<c:import> Include other static or dynamic files into JSP pages. The difference from <jsp:include> is that the latter can only include files in the same web application, while the former can include files in other web applications, or even resources on the network

<c:import url="/cfs/common/baseSelect.jsp" charEncoding="GBK">
		<c:param name="tableName" value="l_sales_channel_mas" />
		<c:param name="selectedId" value="${RESULT.loanMas.salesChannel}" />
</c:import>

<c:catch> is used to handle exceptions generated in JSP pages and store exception information into variables

<c:catch var="msg">  
    <c:redirect url="www.baidu.com"</c:redirect>
</c:catch>

 The fmt tag library is used to format the output, usually time and numbers need to be formatted

<fmt:formatNumber>Format time

<td class="td_3"  align="center"><fmt:formatDate value="${logItem.bookingDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>

<fmt:formatNumber>Format number

<td align="right" class="td_3"><fmt:formatNumber value="${loan.applAmt}" pattern="#,###.##"/></td>





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325690331&siteId=291194637