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"%>



    
hahahah
${number}

Hello World!

问题一:

严重: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.(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即可

Unable to read TLD

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

Unable to read TLD

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

信息: 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" %>

运行效果如下:

  Unable to read TLD

问题二:

严重: 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。
 

 

你可能感兴趣的:(WEB)