JavaWeb part of the video \ 2-12JSP, EL and the JSTL \ Section 5 JSTL commonly used tags

JavaWeb knowledge structure diagram

Section 5 JSTL tags used

JSTL ##
1. concept: JavaServer Pages Tag Library JSP Standard Tag Library
* is a free open source jsp tag <tag> provided by the Apache organization

2. Role: java code and replace the simplified jsp pages

3. Step:
   (1) introducing the relevant jar package jstl

 javax.servlet.jsp.jstl
 jstl-impl

   

   (2) introducing tag library: taglib directive: <% @ taglib%>

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


   (3) Using the tag

 

4. The common JSTL tags
1 if: java code corresponding to the if statement
1. Properties:
* Test properties must accept boolean expressions
* to true if the expression is, if the content of the tag body is displayed, if false, not display tag body content
* In general, Test property value used in conjunction with the expression el
2. Note:
* c: if the label is not the case else, else where you want, you can then define a c: if tag

<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <IF tag>title</ Title > 
</ head > 
< body > 

    <% - 

    C: IF tag 
        1 . Properties:
             * Test properties must accept boolean expressions
                 * if the expression is true, if the content of the tag body is displayed, if false, does not display the contents of the tag body
                 * generally, property value Test used in conjunction with the expression el 

        2 NOTE: c: if the label is not the case else, else where you want, you can define in a c: if tag. 


    - % > 

    < c: IF the Test = "to true" > 
        < h1 > I really ... </ h1 > 
    </ c: IF > 
    < br > 

    <%
        //Request a list of domain determined whether the set is empty, if not null then displayed through the collection 

        List list =  new new the ArrayList (); 
        List.add ( " AAAA " ); 
        request.setAttribute ( " list " , list); 

        request. the setAttribute ( " Number " , . 4 ); 

    %> 

    < C: IF Test = "Not empty List} {$" > 
        through the collection ... 

    </ C: IF > 
    < br > 

    < C: IF Test = "$ {Number % 2! = 0} " >

            $ {number} is an odd number 

    </c:if>

    <c:if test="${number % 2 == 0}">

        ${number}为偶数

    </c:if>

</body>
</html>

 

 

 

 

 

 

 

 


2. choose: java code corresponding to the switch statement
1. Statement labels corresponding to choose switch statement
2. Analyzing the equivalent of using a when labels do Case
3. Statement labels do otherwise corresponds otherwise default

3. foreach: java code equivalent for statement

5. Exercise:
* Demand: The request field has a List collection there User objects. Requires jstl + el data show the list to set the table in a page table jsp

Guess you like

Origin www.cnblogs.com/MarlonKang/p/11440902.html