el表达式和jstl整理

来源:互联网 发布:手机淘宝搜索不到店铺 编辑:程序博客网 时间:2024/06/05 16:59
<c:if test="${empty var1}">
    var1 is empty or null.
</c:if>
<c:if test="${not empty var1}">
    var1 is NOT empty or null.
</c:if>


<c:if test="${fn:length(list)==0}">数组为空</c:if> 


<c:choose>
    <c:when test="${empty var1}">
        var1 is empty or null.
    </c:when>
    <c:otherwise>
        var1 is NOT empty or null.
    </c:otherwise>
</c:choose>


<c:forEach items="${vectors}" var="vector">
<c:out value="${vector}"/>
</c:forEach>

<c:import url="http://www.url.com/edit.js" var="newsfeed"/>


重定向
<c:redirect url="http://www.yourname.com/login.jsp"/>
重定向带参数
<c:redirect url="login.jsp">
<c:param name="id" value="888"/>
</c:redirect>


当要存取的属性名称中包含一些特殊字符,如.或?等并非字母或数字的符号,就一定要使用 []。
例如:${user.My-Name}应当改为${user["My-Name"] }


<%@ taglib prefix="fmt" http://java.sun.com/jsp/jstl/fmt">http://java.sun.com/jsp/jstl/fmt" %>
1)格式化日期<fmt:formatDate value=“” pattern=“yyyy-MM-dd HH:mm:ss”/>
             <fmt:formatDate value="${date }" pattern="yyyy-MM-dd"/>
             <fmt:formatDate value="${date }" pattern="yyyy年MM月dd日"/>                      
2) 格式化数字<fmt:formatNumber  value="${number}" pattern="###,###.##" />
0 0