Unable to read TLD "META-INF/c.tld" from JAR file && JSTL EL表达式无法生效

在使用Intellij Idea学习Web的过程中,因为课程设计需要使用EL表达式,所以需要配置好JSTL。

但在配置的过程,出现两大问题,因为还处于小白阶段,所以花了很长时间解决,最终在CSDN和Stackoverflow的几个帖子中找到了解决方案,这里做个总结。

jsp文件源码如下:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<body>
<c:if test="${1==1}">
    <div>hahahah</div>
</c:if>
<c:forEach var="number" begin="0" end="10" step="1" >
    <div> ${number} </div>
</c:forEach>
<h2>Hello World!</h2>
</body>
</html>

问题一:

严重:servlet.service()for servlet[jsp]in context with path[]threw exception[/index.jsp(line:2,column:61)Unable to read TLD
"META-INF/c.tld"from JAR file"file:/D:/maven/repository/javax/servlet/jsp/jstl/jst1/1.2/jstl-1.2.jar":
org.apache.jasper.JasperException:Failed to load or instantiate TagLibraryvalidator class:org.apache.taglibs.standard.tlv.JstlcoreTLV]
with root cause org.apache.jasper.JasperException:/index.jsp(line:2,column:61)Unable to read TLD"META-INF/c.tld"from JAR file
"file:/D:/maven/repository/javax/servlet/jsp/jstl/jstl/1.2/jstl-1.2.jar":
org.apache.jasper.JasperException:Failed to load or instantiate TagLibraryvalidator class:org.apache.taglibs.standard.tlv.JstlcoreTLV 
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:219)
    at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:182)
    at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:410)
    at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:475)
    at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1427)
    at org.apache.jasper.compiler.Parser.parse(Parser.java:138)
    at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)

这个问题出现的原因是,idea无法读取TLD,也就是“META-INF/c.tld”,所以我下载了standard.jar和jstl.jar,并将standard.jar解压出来的META-INF文件夹(里面包含多个.tld文件)放在WEB-INF下。后来发现,其实不需要解压META-INF/c.tld这些文件,只需要在WEB-INF下添加lib,放standard.jar和jstl.jar即可

运行后,控制台不报错,但运行的界面却依旧无法使用EL表达式,运行效果如下:

运行界面后,控制台出现信息:

信息: At least one JAR was scanned for TLDs yet contained no TLDs. 
Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. 
Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.

本想在stackoverflow中提问,提问中恰巧看到了一个一样的问题,解决方案是:在jsp上添加 isELIgnored="false"

<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" %>

运行效果如下:

 

问题二:

严重: Servlet.service() for servlet [jsp] in context with path [] threw exception 
[javax.servlet.ServletException: java.lang.NoClassDefFoundError: 
org/apache/taglibs/standard/tag/rt/core/IfTag] with root cause
java.lang.ClassNotFoundException: org.apache.taglibs.standard.tag.rt.core.IfTag
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
    at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
    at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
    at org.apache.jsp.index_jsp._jspx_meth_c_005fif_005f0(index_jsp.java:100)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:73)

这也是在解决这个问题中遇到的报错,但解决方案应该还是一样的,在WEB-INF下添加lib,放standard.jar和jstl.jar。
 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值