JSTL Standard Tag Library

Source: Internet
Author: User

1. The Java Server Pages standard Tag Library (JSTL) contains a variety of tags available for use in JSP pages

JSTL Advantages:

    • Provides a standard set of labels
    • Can be used to write various dynamic JSP pages
    • Users access databases, conditionally execute code and support internationalization

2. Core Tag Library

    • Universal tags [scope variables within JSP pages] set remove out
    • conditional tags [various conditions in the JSP page] if choose
    • Iteration Labels

3. For example:

(1) by label

// insert directives that use universal labels
<% @ taglib uri=http://java.sun.com/jstl/core_rt prefix= "C"%>

<body>
<c:set var= "Example" Value= "${100+1}" scope= "Session"/>
set label for setting values and scopes for variables
   <c:out value= "${example}"/>
The result of the Out label display value
   <c:remove var= "Example" scope= "Session"/>
//remove tag to delete a variable with scope
</body>

Case:

• Use common tags in JSP pages set, out, and remove tags
< Body >
<H1> Welcome to Shopstop
The JSP page stores sessionvariable in a variable within a session scope, and other JSP pages in the WEB application can access this variable. <c:set var = "sessionvariable" value= "${90+1}" scope= "session"/>//display its value before deleting sessionvariable: <c:out value= " ${sessionvariable} "/> <c:remove var=" sessionvariable} "scope=" Session "/> </br> display and delete sessionvariabl The value of E. <br/> <c:out var= "${sessionvariable}" >//sessionvariable value is null
</body>

(2) Condition label

Case:

< Body >
<c:if test= "${pagescope.signalstrength<5}" >
<c:set var= "Signalfailure" value= "true" scope= "page"/>
</c:if>
<c:choose>

<c:when test= "${pagescope.signalfailure = = true}" >
Signal Disconnect </c:when> <c:otherwise> signal Open </c:otherwise>

</c:choose>

</body>
<C:choose>   <C:whenTest= "${empty param.username}">Nnknown user. </C:when>   <C:whenTest= "${param.username== ' Tom '}">${param.username} is manager. </C:when>   <c:otherwise>${param.username} is employee. </c:otherwise> </C:choose>The above tag is equivalent to the following Java program fragment:<%  Stringusername=Request.getparameter ("username"); if(username==NULL){    //corresponds to the first<C:when>the body of the label Out.print ("nnknown user."); }Else if(Username.equals ("Tom")){    //corresponds to a second<C:when>the body of the label Out.print (username+"is Manager."); }Else{    //corresponding<c:otherwise>the body of the label Out.print (username+"is employee."); }  %> 

(3) Iteration label

Case:

JSTL Standard Tag Library

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.