JSTL版本問題解決

在學習《JSTL In Action》時試驗了其中第109頁上的例程:
<%@ taglib prefix="c" uri="[url]http://java.sun.com/jstl/core[/url]" %>
<c:set var="totalCount" scope="session" value="100"></c:set>
<c:set var="perPage" scope="session" value="20" ></c:set>
<c:forEach var="boundaryStart" begin="0" end="${totalCount - 1}"
 step="${perPage}">
 <a href="?start=<c:out value="${boundaryStart}"/>"> [ <c:out
   value="${boundaryStart}" /> - <c:out
   value="${boundaryStart + perPage - 1}" /> ] </a>
</c:forEach>
<c:forEach var="current" varStatus="status" begin="${param.start}"
 end="${param.start + perPage - 1}">
 <c:if test="${status.first}">
  <ul>
 </c:if>
 <li>
  <c:out value="${current}" />
 </li>
 <c:if test="${status.last}">
  </ul>
 </c:if>
</c:forEach>
發佈後瀏覽時報下面的錯誤:
org.apache.jasper.JasperException: /jsp/pages/MyJsp.jsp(4,0) According to TLD or attribute directive in tag file, attribute end does not accept any expressions
。。。。
將第一行換成下面的代碼問題即可解決:
<%@ taglib prefix="c" uri="[url]http://java.sun.com/jstl/core_rt[/url]" %>
原因是JSTL的版本問題:
jstl的1.0的版本分爲兩個tld,以core爲例,core.tld和core_rt.tld,後者支持表達式,jstl 1.1的core.tld就都支持了
得益於下面的幫助:
本人試着使用JSTL1.1 發現上面的程序仍然報相同的錯誤. 必須將第一行換成:
<%@ taglib prefix="c" uri="[url]http://java.sun.com/jstl/core_rt[/url]" %>
才正確.
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章