绝对 uri:http://java.sun.com/jsp/jstl/core 无法在 web.xml 或使用此应用程序部署的 jar 文件中解析
Posted
技术标签:
【中文标题】绝对 uri:http://java.sun.com/jsp/jstl/core 无法在 web.xml 或使用此应用程序部署的 jar 文件中解析【英文标题】:The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this app 【发布时间】:2015-04-13 00:14:53 【问题描述】:我对@987654323@中的这个错误有疑问
我也看到过类似的问题,但很奇妙的是我在WEB-INF
下没有任何lib
文件夹!
我正在使用 jdk 1.7
和 netbeans7
和 maven
。
这是我的项目结构:
这是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
文件中访问图像。
更新
我在WEB-INF
下创建了lib
文件夹,并把jstl-1.2.jar
放在上面,如图所示:
但我也有同样的问题。
【问题讨论】:
【参考方案1】:您需要将jstl
标签库添加到WEB-INF/lib
文件夹中。如果没有,则创建 lib
文件夹。
更多关于jstl
here
也将其添加到您的 maven 依赖项中
【讨论】:
见UPDATE
部分。
这可能是因为您的 jsp 位于 WEB-INF/jsp
如何将文件夹添加到 maven?
不是文件夹,是库。你把 jsp 的 Web pages
文件夹移到你那里了吗?
我声明了jst1
对maven的依赖,maven会自动下载它。正如@Neil McGuigan 所说。【参考方案2】:
您需要将jstl标签库添加到WEB-INF/lib文件夹中。如果没有,则创建 lib 文件夹。 从下载 JAR https://mvnrepository.com/artifact/javax.servlet/jstl/1.2
添加 Maven 依赖项不起作用。
【讨论】:
【参考方案3】:在您的 Maven POM 的 <dependencies>
部分中,添加
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
【讨论】:
【参考方案4】:就我而言,我在 pom 上获得了库,但范围为 provided
。
在这种情况下,我们需要在您的服务器上添加库,可能是/lib
或在您的项目中WEB-INF/lib
另一方面,我们可以删除该范围。
【讨论】:
【参考方案5】:很容易修复。在 Netbeans 中左键单击您的项目,单击属性,选择库,然后单击“添加库”。在那里您选择“JSTL 1.2.1”并在对话框中单击新的“添加库”。
【讨论】:
【参考方案6】:请在 im pom.xml 中添加此依赖项。
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
【讨论】:
在哪个文件中添加这个依赖? 如果是maven项目,在pom.xml文件中。以上是关于绝对 uri:http://java.sun.com/jsp/jstl/core 无法在 web.xml 或使用此应用程序部署的 jar 文件中解析的主要内容,如果未能解决你的问题,请参考以下文章