要引用的一些库
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
循环
<c:forEach var="list" items="${moodList }" varStatus="status"> <tr> <td>${status.index+1 }</td> <td> <a target="_blank"><img src="therImg/${list.moodImg }" alt="无法显示该图片"></a></td> </tr> </c:forEach>
时间格式
<td><fmt:formatDate value="${list.updatetime }" pattern="yyyy-MM-dd HH:mm" /></td>
长度判断
<td> <c:if test="${fn:length(list.content)>22}"> <span title="${list.content }"> ${fn:substring(list.content,0,22)}...</span> </c:if> <c:if test="${fn:length(list.content)<=22}"> <span title="${list.content }"> ${list.content }</span> </c:if> </td>
判断
<input type="text" placeholder="请输入关键字" id="customerName" value='<c:if test="${title!=null }">${title }</c:if>' > <c:if test="${articleList.size()>0 }"> <h2>搜索结果</h2> </c:if>
if-else的写法 可嵌套if,when条件为否则执行otherwise
<c:choose> <c:when test="${title!=null }"> <c:forEach items="${articleList }" var="list"> <div class="line"></div> </c:forEach> </c:when> <c:otherwise> <c:forEach items="${articleList }" var="list"> <h2> <a class="text" href="<%=path %>/toDetail?articleId=${list.articleId } " title="${list.articleTitle }" target="_blank">${list.articleTitle }</a> </h2> <div class="line"></div> </c:forEach> </c:otherwise> </c:choose>