Summarize some of the recent gains in jstl, custom jstl labels, and jstl foreach traversing Map

Source: Internet
Author: User
Tags integer division

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.