jstl的错误总结与解决方法(与tomcat版本相关)

来源:互联网 发布:魔兽世界典藏版 淘宝 编辑:程序博客网 时间:2024/06/13 22:21

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,即:

1. http://java.sun.com/jsp/jstl/core;2.http://java.sun.com/jstl/core

但是,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需要的类库到项目中,需要手动导入

0 0
原创粉丝点击