使用Maven将JSTL添加到Tomcat目标webapp

时间:2013-11-19 10:22:51

标签: jsp maven tomcat jstl

当我尝试:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

并运行我的项目,抛出以下异常:

org.apache.jasper.JasperException: 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
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:56)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:445)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:117)
    at org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:311)
    at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:152)
    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)
    at org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

我的pom.xml是:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                        http://maven.apache.org/maven-v4_0_0.xsd"> 


      <modelVersion>4.0.0</modelVersion>
      <groupId>com.asim</groupId>
      <artifactId>project2</artifactId>
      <version>1.0-SNAPSHOT</version>
      <name>project2 Maven Webapp</name>
      <url>http://maven.apache.org</url>

      <dependencies>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

      </dependencies>

    </project>

我的web.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd"
                   version="3.0">

    <display-name>project1</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <filter>
        <filter-name>control</filter-name>
        <filter-class>com.asim.project2.ControlFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>control</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

我正在使用tomcat v7.0。除了库Jre和maven依赖项之外,我的java构建路径中没有任何外部jar。我在web-inf / lib文件夹中没有任何手动添加的jar。我已经浏览了本网站的大部分解决方案,但未能成功。

2 个答案:

答案 0 :(得分:3)

有办法:
使用以下方面的帮助创建了一个新项目: http://fruzenshtein.com/setup-of-dynamic-web-project-using-maven/

将jstl依赖添加为:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
    <scope>runtime</scope>
</dependency>

答案 1 :(得分:0)

我认为你应该在classpath中添加standard-1.1.2.jar。因为这个jar包含文件c.tld,它将提供加载JSTL核心功能的URI。