Introduction to the use of Jstl tags _java

Source: Internet
Author: User

Import JSTL Tag Library

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

Need to import Jstl.jar and Standard.jar

C:foreach--> Iteration Label Iteration list or map

<c:foreach var= "Person" items= "${list}" >
${person.name}</br>
</c:forEach>

<c:foreach var= "entry" items= "${map}" > Iterate over Set collection returned by Map.entryset ()
${entry.key}: ${entry.value}
</c:foreach>

<c:foreach var= "num" begin= "1" end= "9" step= "1" >
${num}
</c:forEach>

<!--${status} Gets an object that contains the current iteration-->
<c:foreach var= "str" items= "${list}" varstatus= "status" >
<tr class= "${status.count%2==0?" Even ': ' Odd '} ' >
</c:forEach>

C:if--> judgment Label
<c:if test= "${user!=null}" var= "result" > user exists, result is true
Welcome: ${user.username}
</c:if>
${result}

C:out

<c:out value= "${data}" default= "AAAAA" escapexml= "true" ></c:out>

C:set

<!--C:set can manipulate each domain JavaBean map Collection-->
<c:set var= "Data" value= "xxxxxx" scope= "page" ></c:set> change the value of data;

<c:set property= "PropertyName" value= "Valuexx" target= "${map}" ></c:set>
${map.propertyname}

<c:set property= "name" value= "uuuuuu" target= "${person}" ></c:set>
${p.name}

C:catch

<c:catch var= "Ex" >
<%
int x = 1/0;
%>
</c:catch>
${ex.message}

C:fortokens--> Split Label

<c:fortokens var= "ss" items= "${data1}" delims= "," >
${SS}
</c:forTokens>
data1={"A,b,c,d"}

C:url--> Generate URL

<c:url var= "Uurrll" value= "/example/ind1ex.jsp" >
<c:param name= "Namechina" value= "China" ></c:param>
</c:url>
<a href= "${uurrll}" >hreftext</a>

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.