zoukankan      html  css  js  c++  java
  • JSTL的基本使用

    <body>
    <%
    request.setAttribute("name", "lisi123");
    request.setAttribute("ttt", new ArrayList());
    request.setAttribute("template", "<h1>lisi123</h1>");
    %>
    <!--
    value:要显示的值
    escapeXml:是否转译html标签 true|false
    default:默认值 当value的值为null的时候 显示 默认值也可以写在标签体之间 default 和标签体之间的内容不能同时存在


    注意 : 最常用的方式是 el表达式


    -->
    <c:out value="${ttt }" escapeXml="false">123</c:out><br>
    ${template }

    ${empty ttt }
    <!--
    在el表达式中 + 表示加和的意思


    -->
    ${"1"+"2" }
    <%-- ${"a"+"b" } --%>
    </body>

    testset.jsp:

    <body>

    <%!

    public static class Users{

    private String name;

    public String getName(){
    return this.name;
    }

    public void setName(String name){
    this.name = name;
    }
    }


    %>
    <!--
    scope:如果不指定 则默认放到 page作用域中 给定的作用域没有scope结尾

    value:存放的值

    var:存放的变量

    target:要更改的那一个对象

    property:要更改的那一个对象中的那一个属性

    常用方式
    value+var+scope
    value+target+property
    -->

    <%
    Users u = new Users();
    u.setName("zhangsan");
    request.setAttribute("user", u);
    %>
    <crazy:set scope="request" value="testset123" var="testset"></crazy:set>
    <crazy:set scope="page" value="testset123456" var="testset"></crazy:set>
    ${requestScope.testset }
    <hr>
    ${user.name }

    <crazy:set property="name" value="lisi" target="${user }"></crazy:set>
    ${user.name }

    <hr>

    <!--
    如果 不指定作用域 会将所有作用域中对应名称的值 一除掉

    -->
    <crazy:remove var="testset" scope="page"/>
    ${testset }
    </body>

    testif.jsp:

    <body>
    <c:set value="11" var="num" scope="request"></c:set>
    <c:if test="${param.num>10 }" var="flag" scope="page">
    <h1 style="color:red">num大于10</h1>
    </c:if>
    <c:if test="${!flag}">
    <h1 style="color:green">num不大于10</h1>
    </c:if>


    <hr>

    <!--
    if(){

    }else if(){

    }else{

    }


    else{

    }if(){

    }else{

    }else[

    }

    -->
    <c:choose>
    <c:when test="${param.num>10 && param.num<20 }"><h1 style="color:red">10 &lt; num &lt; 20</h1></c:when>
    <c:when test="${param.num>20 && param.num<50 }"><h1 style="color:red">20 &lt; num &lt; 50</h1></c:when>
    <c:when test="${param.num<10 }"><h1 style="color:red">num &lt; 10</h1></c:when>
    <c:otherwise><h1 style="color:red">num &gt; 50</h1></c:otherwise>
    </c:choose>
    </body>

    testforeach.jsp:

    <body>
    <%
    List<String> list = new ArrayList<String>();
    for(int i=0;i<20;i++){
    list.add("list"+i);
    }
    request.setAttribute("list", list);
    %>
    <!--
    forEach


    items:待循环的 集合
    var:循环的时候 每次的变量
    step:步进或是 间隔
    begin:从哪一个下标元素开始
    end:在哪一个下标元素结束

    -->

    <c:forEach items="${list }" var="l" step="2" begin="0" end="10" varStatus="s">
    <span>${l }</span>|:|<span>${s.current }|${s.index }|${s.count }|${s.first }|${s.last}</span><br>
    </c:forEach>
    </body>

  • 相关阅读:
    mac使用vnc远程登录ubuntu16.04桌面
    last的用法
    MAC笔记本安装telnet
    lsyncd自动同步配置
    四则运算——安卓版
    敏捷开发方法综述
    数组2——数组首尾相接,求最大子数组
    数组1——求一个数组的最大子数组
    《构建之法》阅读笔记04
    学习进度条——第四周
  • 原文地址:https://www.cnblogs.com/hwgok/p/5840643.html
Copyright © 2011-2022 走看看