1. 程式人生 > >jstl的錯誤總結與解決方法(與tomcat版本相關)

jstl的錯誤總結與解決方法(與tomcat版本相關)

jstl標籤竟然還與tomcat的版本有關。
一會報錯:
java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
這個是你用的tomcat版本低,而jstl標籤的版本高了。(我用的tomcat5.5,jstl1.2)
google一下,說是什麼web.xml版本為2.4要改為2.3,還需要新增一個c.tld的引用。
修改後繼續錯:
The absolute uri: 
http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application


   這個是你的<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>,uri路徑寫錯了,是jstl1.1版本一下的去standard.jar檔案的META-INF中的c.tld中看uri路徑是否多寫了jsp(如:http://java.sun.com/jstl/core)。


不斷的報錯:
java.lang.NoClassDefFoundError: org/apache/taglibs/standard/tag/rt/core/ForEachTag
修改後仍然報錯:
java.lang.NoClassDefFoundError: javax/el/ValueExpression

按照網上所說,更換為jstl1.0.1.jar和standard1.0.1.jar,依舊報錯:

According to TLD or attribute directive in tag file, attribute items does not accept any expressions 


一個上午加上一小半下午時間就在這些錯誤中糾纏過去了,這錯誤真是層出不窮,連連不斷啊、最後一位大神的部落格被我發現,終於解決問題,因為tomcat的版本與jstl以及servlet還需要相容的啊。

servlet/jsp         tomcat
 2.5/2.1             6.0.18
 2.4/2.0             5.5.27
 2.3/1.2             4.1.39
 2.2/1.1              3.3.2(archived)
-----------------------------------------------------------
servlet       jsp      jstl     javaee
  2.5          2.1      1.2       5.0
  2.4          2.0       1.1      1.4
  2.3          1.2       1.0      1.2
  
  
小解釋一下,可能大傢伙都知道了,傳說中的servlet版本可以在web.xml中看到。
如我的tomcat5.5:

Xml程式碼  收藏程式碼
  1. <span style="font-size: medium;"><?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app   
  3.  id="WebApp_ID"   
  4.  version="2.4"   
  5.  xmlns="http://java.sun.com/xml/ns/j2ee"   
  6.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  7.  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  8. </span>  

version=2.4 。

當然也會有些報錯與jar包衝突有關。

兩條解決jstl標籤問題的途徑:1、jar包衝突,覆蓋低版本的jar包即可;2、就需要著重看看是否與tomcat的版本衝突,否則也不能成功。.

經過測試:在jstl1.0以後(jstl1.1,jstl1.2),都包含兩個uri,即:

但是,jstl1.0以後推薦使用第一個uri(我使用第二個uri報錯:According to TLD or attribute directive in tag file, attribute items does not accept any expressions),一定要注意這個細節。

----------------------------------------------------------------------------------------------------------

在tomcat7下執行時,在註釋部分丟擲異常:

LoginGetGameListAction出錯The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

原因分析:tomcat7 不會自動新增jstl需要的類庫到專案中,需要手動匯入