JSTL,EL表达式

1.EL表达式($中间不能有空格{})

  1.布尔型    ${true} <br/>
   2.整型  ${10}  加空格$ {10}<br/>
   3.浮点型 ${10.5}<br/>
   4.空类型${null }  java: <% String a =null; %><%=a %><br/>
   5.字符串型 ${"jl"}<br>
   6.四则运算 ${1+2-1*4/2%2} <br/>
   <%
      //对于集合来说只有存了值,有长度才不是null
      List<String> strList = new ArrayList<String>();
      pageContext.setAttribute("s",strList);
      //对于对象来说,new了之后就不是null
      User user = new User();
      pageContext.setAttribute("u",user);
    %>
   7.empty运算:             ${empty(u) }     ${empty(s) }<br>
   8.判断两个password是否相等:
     <%
      String pwd1 ="1111";
      String pwd2 ="1221f";
      String pwd3 ="1111";
      pageContext.setAttribute("pwd1",pwd1);
      pageContext.setAttribute("pwd2",pwd2);
      pageContext.setAttribute("pwd3",pwd3);
      %>
        ${pwd1 ==  pwd2 }     ${pwd1 == pwd3 }<br/>
   9.错误的写法:
      $ {pwd1 } == ${pwd2 }    $ {${pwd1 } == ${pwd2 } }<br>
   10.从指定域中找:
      <%
        pageContext.setAttribute("password",pwd1);
        request.setAttribute("password",pwd2);
        session.setAttribute("password","9999");
        application.setAttribute("password","0000");
       %>
    ${password}(在最小的域中找)   ${pageScope.password }   ${requestScope.password }
    ${sessionScope.password }  ${applicationScope.password }<br>
  11.查找属性可用"."与"[]":
     ${pageScope.password }   ${requestScope["password"] }<br/>

2.JSTL

   <h1>JSTL:JSP标准标签库</h1>
    <c:if test="${1==1}">
        1=1
    </c:if><br/>
    <%
       List<String > strList = new ArrayList<String>();
       strList.add("1");
       strList.add("2");
       strList.add("3");
       strList.add("4");
       pageContext.setAttribute("strList",strList);
     %>
    <c:forEach var="str" items="${strList}">
      ${str }
    </c:forEach><br/>
    <%
       int a = (int) (Math.random()*4);
       pageContext.setAttribute("a",a);
        Random rand = new Random();  
        int b = rand.nextInt(50)+5;//50~55
        pageContext.setAttribute("b",b);
     %>
    <c:choose>
    <c:when test="${a==1}">
               产生的随机数是1
    </c:when>
     <c:when test="${a==2}">
               产生的随机数是2
    </c:when>
     <c:when test="${a==3}">
               产生的随机数是3
    </c:when>
    <c:when test="${b==55}">
               产生的随机数是50
    </c:when>
    <c:otherwise>
            产生的随机数是4
    </c:otherwise>
    </c:choose>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

兔八哥的幸福生活

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值