昨天是我初次使用JSTL,因為我是用Eclipse開發的,就按照網上的一篇入門文章做下去:
1。下載下傳并解壓了Jakarta jstl 1.1.1.
2. 将解壓後的lib目錄下的兩個jar檔案拷貝到tomcat 下的自己的應用下的WEB-INF/lib目錄下
3。将解壓後的tld目錄下的tld檔案拷貝到到tomcat 下的自己的應用下的WEB-INF/目錄下
4.修改web.xml為以下内容:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
<taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
<taglib-location>/WEB-INF/c-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/sql.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
<taglib-location>/WEB-INF/sql-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/x.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
<taglib-location>/WEB-INF/x-rt.tld</taglib-location>
</taglib>
</web-app>
然後,我把例子jsp加上去(count.jsp):
然後,我把例子jsp加上去(count.jsp):
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<title>Count to 10 Example (using JSTL)</title>
</head>
<body>
<c:forEach var="i" begin="1" end="10" step="1">
<c:out value="${i}" />
<br />
</c:forEach>
</body>
</html>
然後啟動tomcat,開始測試,這時莫名其妙的錯誤出現了:
StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getVariableResolver()Ljavax/servlet/jsp/el/VariableResolver;
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:941)
at org.apache.jsp.teslib3_jsp._jspx_meth_c_out_0(teslib3_jsp.java:143)
at org.apache.jsp.teslib3_jsp._jspx_meth_c_forEach_0(teslib3_jsp.java:113)
at org.apache.jsp.teslib3_jsp._jspService(teslib3_jsp.java:65)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
....
百思不得其解,查文檔有的說是compiler 不對,或者lib沒有加全,我反複檢查均未發現錯誤(java 環境:jsdk1.4.2.7)
StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getVariableResolver()Ljavax/servlet/jsp/el/VariableResolver;
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:941)
at org.apache.jsp.teslib3_jsp._jspx_meth_c_out_0(teslib3_jsp.java:143)
at org.apache.jsp.teslib3_jsp._jspx_meth_c_forEach_0(teslib3_jsp.java:113)
at org.apache.jsp.teslib3_jsp._jspService(teslib3_jsp.java:65)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
....
百思不得其解,查文檔有的說是compiler 不對,或者lib沒有加全,我反複檢查均未發現錯誤(java 環境:jsdk1.4.2.7)
在反複試驗之後,我把web.xml中web-app的xmlns 和xsi屬性去掉(紅色部分),結果ok,但具體原因一直也不清楚,希望高手能說明。