This is a small feature in the company's projects over the past two days. Some jstl labels have been used, but they have not been used before. Now they are basically implemented.
1. The most common use of jstl is if, foreach, and out.
<div class="per-list"> <ul class="list-4"> <li><c:if test="${not empty listqikan }"><c:forEach var="file" items="${listqikan}" varStatus="status"><c:out value="${file['lunwenbiaoti']}"></c:out> </c:forEach></c:if>
</li>
</ul></div>
VaR items varstatus begin end step, which are frequently used
Custom jstl labels
Some features may need to be implemented by ourselves during development, but are the standards provided? We can write
For example, I need to implement integer division and rounding in jstl and apply it to for each.
(1) first write a Java implementation:
Package Org. NSSD. utils; public class jstlfunction {/*** get integer result after division of two numbers ** @ Param first * @ Param second * @ return int */public static int Chufa (INT first, int second) {return first/second ;}}
(2) write your own labels
<? XML version = "1.0" encoding = "UTF-8"?> <Taglib xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version = "2.0"> <tlib-version> 1.0 </tlib-version> <short-Name> Len </short-Name> <function> <description> Chufa </description> <! -- Description of this El Method --> <Name> Chufa </Name> <! -- Call the El method name --> <function-class> Org. NSSD. utils. jstlfunction </function-class> <function-signature> int Chufa (INT, INT) </function-signature> </function> </taglib>
Name myjstl. TLD
Usage: $ {mytag: Chufa (5, 3 )}
The following is a function code for implementing the project:
For each traversal map (MAP also has a list) Map <integer, list <object []>
<Div class = "Total" style = "height: 256px; width: 200px; overflow-Y: auto;"> <ul class = "journallistnum"> <C: if test = "$ {not empty journalnummap}"> <C: foreach Var = "journal" items = "$ {journalnummap}"> <li> <C: out value = "$ {journal. key} "/> <span> year </span> </LI> <ul> <C: If test =" $ {fn: length (Journal. value) <= 10} "> <li> <C: foreach Var =" list "items =" $ {journal. value} "varstatus =" S "> <a href =" <Portlet: renderurl> <Portlet: Param name = "myaction" value = "seeqikan"/> <Portlet: param name = "objectid" value = "$ {Param. objectid} "/> <Portlet: Param name =" name "value =" $ {list [0]} "> </Portlet: param> <Portlet: param name = "qikanzhongwenming" value = "$ {list [4]}"> </Portlet: param> </Portlet: renderurl> ">$ {S. index + 1} </a> <span> </C: foreach> </LI> </C: If> <C: if test = "$ {fn: length (Journal. value)> 10} "> <C: foreach end =" $ {mytag: Chufa (FN: length (Journal. value), 10)} "begin =" 1 "step =" 1 "varstatus =" S "> <li> <C: foreach Var = "list" items = "$ {journal. value} "begin =" $ {(S. index-1) * 10} "End =" $ {S. index * 10-1} "step =" 1 "varstatus =" SS "> <a href =" <Portlet: renderurl> <Portlet: param name = "myaction" value = "seeqikan"/> <Portlet: Param name = "objectid" value = "$ {Param. objectid} "/> <Portlet: Param name =" name "value =" $ {list [0]} "> </Portlet: param> <Portlet: param name = "qikanzhongwenming" value = "$ {list [4]}"> </Portlet: param> </Portlet: renderurl> ">$ {ss. index + 1} </a> <span> </C: foreach> </LI> </C: foreach> <li> <C: foreach Var = "list" items = "$ {journal. value} "begin =" $ {mytag: Chufa (FN: length (Journal. value), 10) * 10} "End =" $ {fn: length (Journal. value)-1} "step =" 1 "varstatus =" SS "> <a href =" <Portlet: renderurl> <Portlet: param name = "myaction" value = "seeqikan"/> <Portlet: Param name = "objectid" value = "$ {Param. objectid} "/> <Portlet: Param name =" name "value =" $ {list [0]} "> </Portlet: param> <Portlet: param name = "qikanzhongwenming" value = "$ {list [4]}"> </Portlet: param> </Portlet: renderurl> ">$ {ss. index + 1} </a> <span> </C: foreach> </LI> </C: If> </ul> </C: foreach> </C: If> </ul> </div>