首页 > Web开发 > 详细

JSP中常用的的EL表达式的汇总

时间:2019-04-25 12:39:03      阅读:127      评论:0      收藏:0      [点我收藏+]

Jsp基础知识

  • jsp的组成

    1. html静态页面(css、javascript)
    2. java代码 <% %> (_jspService方法中)
    3. 内置对象 out request
    4. 表达式 <%= %>
    5. 声明方法和成员变量 <%! %>
    6. 指令 %@page %@include
    7. 动作 jsp:include jsp:forward
    8. 注释 <%-- --%>
  • 包含关系

    • 静态包含 <%@include file="footer.jsp" %>
    • 动态包含 <jsp:includ e page="header.jsp">
  • 静态包含和动态包含的区别

     原理是否生产java文件是否生可以有同名变量包含的时机
    动态包含 方法的调用 生成 可以 执行class文件
    静态包含 内容嵌套 不生成 不可以 转译

EL表达式

  • jar的引用

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
  • 常用语法

    • for循环

      <c:forEach items="${recommendList}" var="item">
          ${item.desc}
      </c:forEach>
      <!--利用下标取出前四个元素 status-->
      <c:forEach items="${split}" var="subString" varStatus="status">
          <c:if test="${status.index < 4}">
              <li class=""><img src="${baseUrl}${subString}" alt="用户配图丢失">
          </c:if>
      </c:forEach>
      <!-- 取出123 -->
      <c:forEach var="x" begin="1" end="${pageProductHot.extra.listPageCount}">
          <a href="${baseUrl}product/jsp/indexForH5.jsp">${x}</a>
      </c:forEach>
    • if判断

      <!--取出前五个元素 -->
      <c:forEach items="${pageProductHot.list}" var="item" varStatus="status">
      <c:if test="${(status.index) < 5}">
          ${item.name}
      </c:if>   
      </c:forEach>
      <!--判断字符串是否为“” 判断是否为null-->
      <c:if test="${not empty item.coverImgUrl || item.coverImgUrl eq null}">
      
      </c:if>
      <!--分割字符串 并且判断字符串长度-->
      <c:set value="${fn:split(item.imgUrls, ‘,‘) }" var="split" />
          <c:if test="${fn:length(‘${split}‘) == 1}"
          <img src="${baseUrl}${split[0]}">
          
          <c:if test="${fn:length(item.textContentShort) > 100}">
          </c:if>
      </c:if>
    • split分割字符串

      <!--分割字符串 得到字符串数组-->
      <c:set value="${fn:split(item.imgUrls, ‘,‘) }" var="split" />
    • replace替换字符串中的内容

      <c:set var="newLine" value="\r\n" />
      ${fn:replace(product.loanRequire, newLine, "<br />")}

       

JSP中常用的的EL表达式的汇总

原文:https://www.cnblogs.com/tujietg/p/10767664.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!