Jsp judges the List length and jsplist length.

Source: Internet
Author: User

Jsp judges the List length and jsplist length.

Hello everyone:

One problem encountered today is that the back-end uploads a List to the front-end and the front-end judges the List length!

Other tags are required to search for other users.

<Span style = "font-size: 14px; color: # cc0000;"> in jsp development, you often need to determine the length of the list or string to do something, because if in the jstl label does not support else, select while. <% @ Taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> <% @ taglib uri = "http://java.sun.com/jsp/jstl/functions" prefix = "fn" %> -------- standard is required here. after the jar package introduces two tag libraries, the length can be determined. For example, Jsp code is added to the favorites Code <c: choose> <c: when test = "$ {fn: length (contact. <span class = "grouped"> ungrouped </span> </c: when> <c: otherwise> <c: forEach items = "$ {contact. tagscholar} "var =" tags "> <span class =" grouped ">$ {tags. tagname} </span> </c: forEach> </c: otherwise> </c: choose> </span>
What I want to talk about today is just the tag <% @ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>.

You only need to add an implicit tag to the body to easily determine

<Input type = "hidden" name = "tcMedicineList" value = "$ {tcMedicineList}"/>

<C: if test = "$ {tcMedicineList. size ()> 2}">

So OK !!!

<Span style = "font-size: 14px; "> <body> <input type =" hidden "name =" tcMedicineList "value =" $ {tcMedicineList} "/> <input type =" hidden "name =" weMedicineList "value = "$ {weMedicineList}"/> <input type = "hidden" name = "otMedicineList" value = "$ {otMedicineList}"/> <input type = "hidden" name = "trMedicineList" value = "$ {trMedicineList}"/> <input type = "hidden" name = "ptcMedicineList" value = "$ {ptcMedicineList}"/> <! -- Recipe start --> <div class = "container"> <dl class = "recipe_pay_detail recipe_detail"> <dt class = "medicine_head"> <I class = "ico ico_recipe recipe_bg6"> </I> traditional Chinese medicine: </dt> <dd id = "medicine_info_chn"> </span> <span style = "font-size: 18px; color: # ff6600; "> <span style =" background-color: rgb (102, 0,204); "> <c: forEach items = "$ {tcMedicineList}" var = "tcMedicineList" begin = "0" end = "1"> </span> <span style = "colo R: rgb (255,102, 0); font-size: 18px; font-family: Arial, Helvetica, sans-serif; "> </span> <span style =" color: rgb (255,102, 0); font-size: 18px; font-family: Arial, Helvetica, sans-serif; "> <! -- Loop List only displays the first two --> </span>
<Span style = "font-size: 14px;"> <p> <span >$ {tcMedicineList. name} </span >$ {tcMedicineList. standard} </p> </c: forEach> </span> <strong style = "font-size: 14px; "> </strong> <span style =" font-size: 18px; "> </span> <span style =" color: # ff9900; "> <span style =" font-size: 18px; "> <span style =" background-color: rgb (51,102,255); "> <c: if test = "$ {tcMedicineList. size ()! = 0 & 2> tcMedicineList. size ()} "> </span> <span style =" font-size: 14px; "> </span> <span style =" color: rgb (255,102, 0); font-size: 18px; font-family: Arial, Helvetica, sans-serif; "><! -- If the number of List entries is not equal to 0 and the number of entries is smaller than 2 --> </span> <span style = "font-size: 14px;"> <span style = "color: # ff9900; "> </span> <c: forEach items =" $ {ptcMedicineList} "var =" ptcMedicineList "<span style =" background-color: rgb (51,102,255 ); "> <span style =" color: # ff0000; "> begin =" 0 "end =" 0 "</span> <p> dose: $ {ptcMedicineList. num }$ {ptcMedicineList. unit} <br/> <% -- dose: $ {ptcMedicineList. dosage} <br> -- %> usage: $ {ptcMedicineList. us Emethod }$ {ptcMedicineList. dosage} </p> </c: forEach> </c: if> <c: if test = "$ {tcMedicineList. size ()> 2} "> </span> <span style =" color: rgb (255,102, 0); font-family: Arial, Helvetica, sans-serif; font-size: 18px; "> <! -- If the number of List entries is greater than 2 --> </span> <span style = "font-size: 14px;"> <c: forEach items = "$ {ptcMedicineList}" var = "ptcMedicineList" <span style = "background-color: rgb (51,102,255);"> <span style = "color: # ff6600; "> begin =" 0 "end =" 0 "> </span> <span style =" color: # ffff66; ">></span> <span style =" color: rgb (255,102, 0); font-family: Arial, Helvetica, sans-serif; font-size: 18px; "> <! -- Only the previous one is displayed in the cyclic List --> </span> <span style = "font-size: 14px;"> <p> dose: $ {ptcMedicineList. num }$ {ptcMedicineList. unit} <br/> usage: $ {ptcMedicineList. usemethod }$ {ptcMedicineList. dosage} <a href = "#" class = "btn btn_o_c btn_open" id = "btn_open_chn"> Expand </a> </p> </c: forEach> </c: if> </dd> <dd id = "medicine_detail_chn"> <c: forEach items = "$ {tcMedicineList}" var = "tcMedicineList"> <p> <span >$ {tcMedicineList. name} </span> $ {TcMedicineList. standard} </p> </c: forEach> <c: forEach items = "$ {ptcMedicineList}" var = "ptcMedicineList" begin = "0" end = "0"> </span> <span style = "color: rgb (255,102, 0); font-family: Arial, Helvetica, sans-serif; font-size: 18px; "> <! -- Only the previous one is displayed in the cyclic List --> </span> <span style = "font-size: 14px;"> <p> dose: $ {ptcMedicineList. num }$ {ptcMedicineList. unit} <br/> usage: $ {ptcMedicineList. usemethod }$ {ptcMedicineList. dosage} <a href = "#" class = "btn btn_o_c btn_close" id = "btn_close_chn"> collapse </a> </p> </c: forEach> </dd> <dt class = "medicine_head"> <I class = "ico ico_recipe recipe_bg4"> </I> Western medicine: </dt> <dd id = "medicine_info"> <c: forEach items = "$ {weMedicineList}" var = "weMedicineList" begin = "0" end = "1"> <p> <span >$ {weMedicineList. name} </span >$ {weMedicineList. standard} </p> </c: forEach> <c: if test = "$ {weMedicineList. size ()> 2} "> <p>... <a href = "#" class = "btn btn_o_c btn_open" id = "btn_open"> Expand </a> </p> </c: if> </dd> <dd id = "medicine_detail"> <c: forEach items = "$ {weMedicineList}" var = "weMedicineList"> <p> <span >$ {weMedicineList. name} </span >$ {weMedicineList. standard} </p> </c: forEach> <p> <a href = "#" class = "btn btn_o_c btn_close" id = "btn_close"> collapse </a> </p> </dd> <% -- <dt> <I class = "ico ico_recipe recipe_bg4"> </I> check items: </dt> <dd id = "medicine_info_check"> <c: forEach items = "$ {entity}" var = "entity" begin = "0" end = "1"> <p> <span >$ {entity. name} </span> </p> </c: forEach> <p> <a href = "#" class = "btn btn_o_c btn_open" id = "btn_open"> Expand </a> </p> </dd> <dd id = "maid"> <c: forEach items = "$ {entity}" var = "entity"> <p> <span >$ {entity. name} </span> </p> </c: forEach> <p> <a href = "#" class = "btn btn_o_c btn_close" id = "btn_close"> collapse </a> </p> </dd> -- %> <dt> <I class = "ico ico_recipe recipe_bg5"> </I> others: </dt> <dd> <c: forEach items = "$ {otMedicineList}" var = "otMedicineList"> <p> <span >$ {otMedicineList. name} </span >$ {otMedicineList. standard} </p> </c: forEach> </dd> <dt> <I class = "ico ico_recipe recipe_bg2"> </I> treatment items: </dt> <c: forEach items = "$ {trMedicineList}" var = "trMedicineList"> <dd> <p> <span >$ {trMedicineList. name} </span >$ {trMedicineList. standard} </p> </dd> </c: forEach> <dd class = "recipe_sum sum_all"> total: $ {RMB} RMB </dd> </dl> </div> </span>




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.