绝对的uri:http://java.sun.com/jsp/jstl/core无法在web.xml或使用此应用程序部署的jar文件中解析

时间:2015-02-12 10:00:44

标签: java xml spring jsp maven

我在spring mvc

中遇到此错误的问题

我看到了类似的问题,但很棒的是我lib下没有任何WEB-INF文件夹!

我正在使用jdk 1.7netbeans7以及maven

这是我的项目结构:

enter image description here

这是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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.sajjad</groupId>
    <artifactId>OnlineBookStore2</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>OnlineBookStore2</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>org-apache-commons-logging</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>cglib-2.2</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-aop-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-aspects-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-beans-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-build-src-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-context-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-context-support-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-core-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-expression-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-framework-bom-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-instrument-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-instrument-tomcat-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-jdbc-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-jms-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-messaging-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-orm-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-oxm-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-test-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-tx-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-web-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-webmvc-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-webmvc-portlet-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>spring-websocket-4.0.1.RELEASE</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.1.Final</version>
        </dependency>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>hibernate-jpa-2.1-api-1.0.0.Final</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>unknown-jars-temp-repo</id>
            <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
            <url>file:${project.basedir}/lib</url>
        </repository>
    </repositories>
</project>

这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

这是我的dispatcher-servlet.xml

<?xml version='1.0' encoding='UTF-8' ?>
<beans xsi:schemaLocation="http://www.springframework.org/schema/beans
                          http://www.springframework.org/schema/beans/spring-beans.xsd
                          http://www.springframework.org/schema/context
                          http://www.springframework.org/schema/context/spring-context.xsd
                          http://www.springframework.org/schema/mvc
                          http://www.springframework.org/schema/mvc/spring-mvc.xsd"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"> 

    <context:component-scan base-package="sajjad.htlo"/> 
    <mvc:annotation-driven/>

    <mvc:resources mapping="/resources/**" location="/resources/pics/" />
    <mvc:default-servlet-handler/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="viewResolver">
        <property name="prefix"> 
            <value>/WEB-INF/jsp/</value> 
        </property> 
        <property name="suffix"> 
            <value>.jsp</value> 
        </property> 
    </bean>
</beans>

我的控制器类:

@Controller
public class IndexController {
    @RequestMapping(value = "/index.html")
    public ModelAndView indexPage() {
        return new ModelAndView("index");
    }
}

我的观点jsp档案:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Welcome</title>
    </head>
    <body>
        this is index page
        <img src="resources/pics/t3.jpg" />
    </body>
</html>

当我尝试:http://localhost:8080/OnlineBookStore2/index.html发生此错误:

HTTP Status 500 - 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
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
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:56)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:445)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:117)
...

我将从jsp文件访问图片。

更新

我在lib下创建了WEB-INF文件夹并将jstl-1.2.jar放在其上,如图所示:

enter image description here

但我还有同样的问题。

6 个答案:

答案 0 :(得分:4)

您需要将jstl标记库添加到WEB-INF/lib文件夹。如果您没有,请创建lib文件夹。

有关jstl here

的更多信息

还要将其添加到您的maven依赖项

答案 1 :(得分:1)

您需要将jstl标记库添加到WEB-INF / lib文件夹中。如果你没有一个你创建lib文件夹。 从中下载JAR https://mvnrepository.com/artifact/javax.servlet/jstl/1.2

添加Maven依赖项不起作用。

答案 2 :(得分:0)

在Maven POM的<dependencies>部分,添加

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

答案 3 :(得分:0)

在我的情况下,我在pom上安装了库,但范围为provided

在这种情况下,我们需要在您的服务器上添加该库,可能是/lib或您的项目WEB-INF/lib

另一方面,我们可以删除该范围。

答案 4 :(得分:0)

修复非常简单。在Netbeans中左键单击您的项目,单击属性,选择库,然后单击“添加库”。在那里选择“JSTL 1.2.1”并在对话框中单击新的“添加库”。

答案 5 :(得分:0)

请添加此依赖关系im pom.xml。

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