JSTL 标签库

  • out 标签
    value:输出值,default:默认输出值,escape:特殊字符是否转义
    <c:out value="<Hello World!>" default="defalut" escapeXml="false">
    HtmlUtils.htmlUnescape(help); -> 富文本不转义(Spring)
  • redirect 标签
        <c:url var="url" value="index.jsp">
            <c:param name="name" value="wjx"/>
            <c:param name="pass" value="xjw"/>
        </c:url>
        <c:redirect url="${url}"/>
  • set 标签
    <c:set value="wjx" var="wjx" scope="request"></c:set> -> 方式一
    <jsp:useBean id="person" class="bean.Person"/> -> 方式二
    <c:set target="${person}" property="name" value="123"/> -> 赋值
  • remove 标签
    <c:remove var="wjx" scope="request"/> -> 请求域移除参数
  • if 标签
    结果为True,执行标签体
    <c:if test="${not empty tag}">
         <c:if test="${tag eq 'new'}">
                <i onclick="window.location.href='${url}'">new</i>
         </c:if>
    </c:if>
  • case 标签
    <%--大写转换小写--%>
    ${fn:toLowerCase("ITCAST")}<br>
    <%--小写转换大写--%>
    ${fn:toUpperCase("wjx")}
  • fn:contains 标签
    <%--区别大小写--%>
    ${fn:contains("wjx","w")};<br>
    ${fn:contains("wjx","W")};<br>
    <%--不区别大小写--%>
    ${fn:containsIgnoreCase("wjx","w" )};<br>
    ${fn:containsIgnoreCase("wjx","W" )};<br>
  • fn:escapeXml 标签
    ${fn:escapeXml("<br>")}<br>
    <c:out value="<br>" escapeXml="true" default="转义"></c:out><br>
    ${"<b>我</b>"}
  • fn:indexOf 标签
    ${fn:indexOf("wjx","w" )}<br>
    ${fn:indexOf("wjx","j" )}<br>
    ${fn:indexOf("wjx","x" )}<br>
  • fn:join 标签
    <%  String strs[]={"www","itcast","com"};  %>
    <c:set var="strs" value="<%=strs%>"/>
    ${fn:join(strs,".")}
  • fn:length 标签
    <%
    int[] array={1,2,3,4};
    List list = new ArrayList();
    list.add("one");
    list.add("two");
    list.add("three");
    %>

    <c:set value="<%=array%>" var="array"/>
    <s:set value="<%=list%>" var="list"/>
    数组长度:${fn:length(array)}<br>
    集合长度:${fn:length(list)}<br>
    字符串长度:${fn:length("Tomcat")}<br>
  • fn:replace 标签
    <%--字符串替换--%>
    ${fn:replace("w.j.x","." ,"" )}
  • fn:split 标签
    <c:set var="strs" value='${fn:split("w j x"," ")}'/>
    <c:forEach var="each" items="${strs}" >
        <c:out value="${each}" escapeXml="true" default="sss"/><br>
    </c:forEach>
  • fn:substring 标签
    <%--字符串抽取--%>
    ${fn:substring("wjx",0 ,2 )}<br>
    ${fn:substringBefore("wjx", "j")}<br>
    ${fn:substringAfter("wjx","j" )}
  • fn:trim 标签
    <%--清除字符串前后的空格--%>
    ${fn:trim("wjx")}
  • fn:startsWith 标签 、fn:endsWith 标签
    <%--开头--%>
    ${fn:startsWith("wjx","w")}<br>
    ${fn:startsWith("wjx","j")}<br>
    <%--结束--%>
    ${fn:endsWith("wjx","x" )}<br>
    ${fn:endsWith("wjx","j" )}<br>
  • catch 标签
    <c:catch var="wjx">
        <%
        int j=10;
        int i=0;
        System.out.println(j/i);
        %>
    </c:catch>
  • choose 标签
    <c:choose>
        <c:when test="${empty param.username}">
            param没有参数
        </c:when>
        
        <c:when test="${param.username=='wjx'}">
            wjx
        </c:when>

        <c:otherwise>
            else
        </c:otherwise>
    </c:choose>
  • forEach 标签
<%--数组--%>
<%
    String[] fruits = {"apple", "orange", "grape", "banana"};
%>
<c:forEach var="wjx" items="<%=fruits%>">
    ${wjx}<br>
</c:forEach>

<%--Map集合--%>
<%
    Map map = new HashMap();
    map.put("Tom", "123");
    map.put("Mike", "123");
    map.put("Lina", "123");
%>
<c:forEach var="map" items="<%=map%>">
    ${map.key}&nbsp; ${map.value}<br>
</c:forEach>

<%--List集合--%>
<%
    List list = new ArrayList();
    list.add("red");
    list.add("yellow");
    list.add("blue");
    list.add("green");
%>
<c:forEach var="color" items="<%=list%>" begin="0" end="3" step="1" varStatus="status">
    ${!status.first} -> 第一个Item
    ${!status.last} -> 最后一个Item
    ${color} <br/>
</c:forEach>


  • forTokens 标签
<c:forTokens var="token" items="Spring,Summer|autumn,winter" delims="|,">
    ${token}
</c:forTokens> 
  • formatDate 标签
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatDate type="date" value="${withdraw.createDate}" />
  • EL表达式的判断符号
                     等于  ==    eq 
                   不等于  !=    ne、neq
                     大于  >     gt 
                     小于  <     lt 
                 大于等于  >=    ge、gte
                 小于等于  <=    le、lte
                       与  &&    and 
                       或  ||    or 
                       非  !     not 
                       加  + 
                       减  - 
                       乘  * 
                     除以  /     div 
                     求莫  %     mod 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • JSTL标签库的使用是为弥补html标签的不足,规范自定义标签的使用而诞生的。使用JSLT标签的目的就是不希望在j...
    重山杨阅读 3,816评论 0 3
  • 温馨提示:本文阅读需要8分钟,建议收藏后阅读! EL表达式很厉害对不对 今天我们来一个更厉害的JSTL “为什么说...
    Java联盟阅读 4,994评论 0 1
  • 主要内容:(工程el_example中6.jsp) <c:out>标签 <c:set>标签 <c:remove>标...
    yjaal阅读 3,287评论 0 5
  • JSPL JSP标准标签库 作用: 和 EL 表达式一起,取代<% %>java代码 JSTL标签库 核心标签库(...
    老茂在北京阅读 1,813评论 0 0
  • JSTL apache对EL表达式的扩展 jstl.jar包core 核心库fmt 格式化标签库 Core (c标...
    大批阅读 1,521评论 0 0