我不知道我做错了什么,但是我不能包括JSTL。我有jstl-1.2.jar,但不幸的是我得到了例外:
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51) at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409) at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116) at org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:315) at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:148) at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:429) at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:492) at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1439) at org.apache.jasper.compiler.Parser.parse(Parser.java:137) at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255) at org.apache.jasper.compiler.ParserController.parse(ParserController.java:103) at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:170) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:332) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:312) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:299) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Thread.java:619)
我有:
pom.xml
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
index.jsp
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <html> <head></head> <body></body> </html>
org.apache.jasper.JasperException:绝对uri:http : //java.sun.com/jstl/core不能在web.xml或与此应用程序一起部署的jar文件中解析
该URI适用于JSTL 1.0,但是您实际上使用的是JSTL 1.2,它使用带有附加/jsp路径的URI (因为发明EL表达式的JSTL自1.1版起就作为JSP的一部分集成在一起,以便在其中共享/重用EL逻辑。普通的JSP)。
/jsp
因此,请相应地修复taglib URI:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
此外,您的POM还通过指定了Apache的JSTL 1.1实现taglibs:standard。当您已经通过捆绑了JSTL 1.2 API + impl时,这是不必要的,甚至是危险的javax.servlet:jstl,因为1.1和1.2显然会相互冲突。只是 只有 下列JSTL 1.2的依赖应该这样做,以安装在你的Tomcat针对性的webapp JSTL(也 未 设置<scope>到provided比如Tomcat居然不提供开箱!):
taglibs:standard
javax.servlet:jstl
<scope>
provided
<dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
非Maven用户可以通过将单个jstl-1.2.jar文件拖放/WEB- INF/lib到Web应用程序项目的文件夹中来实现相同目的(不要 在其中 拖放standard.jar或任何松散的.tld文件!)。
/WEB- INF/lib
如果您实际上使用的是普通的Java EE服务器(如WildFly,Payara等)而不是诸如Tomcat,Jetty等的准系统servlet容器,那么您根本不需要显式安装JSTL。普通的Java EE服务器已经提供了JSTL。换句话说,您无需向pom.xmlWebapp中添加JSTL 或删除任何JAR / TLD文件。仅provided限定范围的Java EE坐标就足够了:
<dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version><!-- 8.0, 7.0, etc depending on your server --></version> <scope>provided</scope> </dependency>
此外,您还应确保声明您web.xml的声明 至少 符合Servlet 2.4,因此不符合Servlet 2.3或更早的版本。否则,JSTL标记内的EL表达式将无法正常工作。选择与目标容器匹配的最高版本,并确保您的容器中没有<!DOCTYPE>任何位置web.xml。这是一个与Servlet 4.0(Tomcat 9)兼容的示例:
<!DOCTYPE>
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <!-- Config here. --> </web-app>