【问题标题】:The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved [duplicate]绝对uri:http://java.sun.com/jsp/jstl/core 无法解析[重复]
【发布时间】:2011-08-05 04:07:09
【问题描述】:

我拿起了一个新创建的 maven webapp 项目,并想用它做最简单的 mvc 应用程序。我的环境是这样的:

<artifactId>spring-core</artifactId>
        <artifactId>spring-test</artifactId>
        <artifactId>spring-beans</artifactId>
        <artifactId>spring-context</artifactId>
        <artifactId>spring-aop</artifactId>
        <artifactId>spring-context-support</artifactId>
        <artifactId>spring-tx</artifactId>
        <artifactId>spring-orm</artifactId>  
        <artifactId>spring-web</artifactId>
        <artifactId>spring-webmvc</artifactId>
        <artifactId>spring-asm</artifactId>
        <artifactId>log4j</artifactId>
        <artifactId>hibernate-core</artifactId>
        <artifactId>hibernate-cglib-repack</artifactId>
        <artifactId>hsqldb</artifactId>

        <!-- particular arears-->
         <dependency>
           <groupId>taglibs</groupId>
           <artifactId>standard</artifactId>
           <scope>provided</scope>
        </dependency>
        <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>servlet-api</artifactId>
           <scope>provided</scope>
        </dependency>
        <!-- -->

       <spring.version>3.0.5.RELEASE</spring.version>
       <hibernate.version>3.6.1.Final</hibernate.version>
       <hibernate-cglig-repack.version>2.1_3</hibernate-cglig-repack.version>
       <log4j.version>1.2.14</log4j.version>
       <javax-servlet-api.version>2.5</javax-servlet-api.version>
       <hsqldb.version>1.8.0.10</hsqldb.version>
       <mysql-connector.version>5.1.6</mysql-connector.version>
       <slf4j-log4j12.version>1.5.2</slf4j-log4j12.version>
       <slf4j-api.version>1.5.8</slf4j-api.version>
       <javaassist.version>3.7.ga</javaassist.version>
       <taglibs.version>1.1.2</taglibs.version>


        <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1-beta-1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
    <finalName>admin-webapp</finalName>
</build>
<profiles>
    <profile>
        <id>endorsed</id>
        <activation>
            <property>
                <name>sun.boot.class.path</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.0.2</version>
                    <configuration>
                        <!-- javaee6 contains upgrades of APIs contained within the JDK itself.
                             As such these need to be placed on the bootclasspath, rather than classpath of the
                             compiler.
                             If you don't make use of these new updated API, you can delete the profile.
                             On non-SUN jdk, you will need to create a similar profile for your jdk, with the similar property as sun.boot.class.path in Sun's JDK.-->
                        <compilerArguments>
                            <bootclasspath>${settings.localRepository}/javax/javaee-endorsed-api/6.0/javaee-endorsed-api-6.0.jar${path.separator}${sun.boot.class.path}</bootclasspath>
                        </compilerArguments>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>javax</groupId>
                            <artifactId>javaee-endorsed-api</artifactId>
                            <version>6.0</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <netbeans.hint.deploy.server>Tomcat60</netbeans.hint.deploy.server>
    <tomcat.home>${env.CATALINA_HOME}</tomcat.home>
    <web.context>${project.artifactId}</web.context>
</properties>

我的 applicationContext 很简单:

<context:component-scan base-package="com.personal.springtest.admin.webapp" />
<mvc:annotation-driven />

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_3_0.xsd"
 version="3.0">
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

<servlet>
    <servlet-name>iwadminservlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/project-admin-webapp-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

   <servlet-mapping>
    <servlet-name>iwadminservlet</servlet-name>
    <url-pattern>/</url-pattern>
   </servlet-mapping>
</web-app>

我的控制器是这样的:

@Controller
public class HomeController {

   @RequestMapping(value="/")
   public String Home(){
    System.out.print("THIS IS a demo mvc, i think i like it");
    // this is temporary, will use viewresolver when everything clears up
    return "/views/home.jsp";
   }

}

我的看法是:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    "http://www.w3.org/TR/html4/loose.dtd">
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>JSP Page</title>
   </head>
   <body>
      <h1>Hello World!</h1>
   </body>
</html>

我得到的错误是

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

问题 1:我想知道是不是因为我正在使用的版本,我想我已经阅读了一些关于 tomcat 中支持的版本,以及使用的 java ee 版本。don' t 真的从中得到解决我的问题的方法。我怎样才能解决这个问题?

问题 2:在出现此错误之前,我的代码为 400,因为我没有正确地将其指向 views/home.jsp,但我确实注意到当我在 netbeans 中运行该应用程序时,它会打开浏览器使用网址:http://localhot:8080/ 而我期待 http://localhost:8080/admin-webapp/ admin-webapp 是我的战争名称。我相信这是一个问题,并想解决它。

【问题讨论】:

  • Tomcat 确实根本不附带 JSTL。在我们的 JSTL wiki 页面上阅读更多信息:stackoverflow.com/questions/tagged/jstl
  • 感谢您的回答,关于问题 2 的任何想法。它似乎与我很接近

标签: java tomcat spring-mvc jstl


【解决方案1】:

您需要 JSTL 实现:

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

或者如果您手动包含 JSTL jar:

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

【讨论】:

  • 感谢杰夫,它现在已修复。这个问题对我来说也很重要。应用程序仍然从 http://localhost:8080/ 而不是 http://localhost:8080/nameofmywar/ 开始,如何解决?谢谢
  • 听起来这不是您的应用程序的真正问题,而是您想在 NetBeans 中编辑运行配置。在 NetBeans 项目属性的“运行”类别下,“上下文路径”设置是什么?听起来好像没有上下文路径,或者它设置为根 (/)。如果为空,则输入“admin-webapp”。
【解决方案2】:
  1. here 下载 JSTL API 和 JSTL 实现
  2. 添加此指令:&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;

  3. 将 JAR 文件粘贴到您的 WEB-INF/lib 文件夹中。这应该有效。 (它 为我工作。)

【讨论】:

    猜你喜欢
    • 2014-09-03
    • 2011-05-28
    • 1970-01-01
    • 2013-04-28
    • 2013-10-27
    • 2010-12-26
    • 2020-11-10
    • 2016-06-22
    相关资源
    最近更新 更多