本文介绍了如何安装JSTL?绝对URI:无法解析http://java.sun.com/jsp/jstl/core的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的JSP页面的taglib指令:

This is my JSP page's taglib directive:

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


我收到以下错误消息:


I'm getting the following ERROR :

HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
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:51)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116)
org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:315)
org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:148)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:420)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:476)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1426)
org.apache.jasper.compiler.Parser.parse(Parser.java:133)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:215)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


我在/WEB-INF/lib 文件夹中添加了JAR文件 jstl.jar standard.jar .
谁能告诉我我在哪里犯错了?


I have added the JAR file jstl.jar and standard.jar in the /WEB-INF/lib folder.
Can anyone tell me where I'm making the mistake?

推荐答案

看起来您正在使用带有1.1/1.2的taglib URI的JSTL 1.0.您有不同版本的JSTL:

It look like that you're using JSTL 1.0 with taglib URIs of 1.1/1.2. You have JSTL in different versions:

  • 1.0 :存在两个JAR文件jstl.jarstandard.jar. Taglib URI的路径中没有/jsp,并且库名后缀有_rt,例如http://java.sun.com/jstl/core_rt.至少需要Servlet 2.3/JSP 1.2.是生命的尽头,请不要在今天使用它.
  • 1.1 :与1.0具有相同的JAR文件. Taglib URI没有后缀,并且在http://java.sun.com/jsp/jstl/core之类的路径中包含/jsp.出现并至少需要Servlet 2.4/JSP 2.0.
  • 1.2 :存在一个JAR文件jstl-1.2.jar,并且具有与1.1相同的tagtlib URI.随Servlet 2.5/JSP 2.0一起出现,但也适用于Servlet 2.4/JSP 2.0.
  • 1.0: exist of two JAR files jstl.jar and standard.jar. Taglib URI is has no /jsp in path and library name is suffixed with _rt like http://java.sun.com/jstl/core_rt. Came along and requires at minimum Servlet 2.3 / JSP 1.2. Is end of life, do not use it nowadays.
  • 1.1: exist of same JAR files as 1.0. Taglib URI has no suffix and includes /jsp in the path like http://java.sun.com/jsp/jstl/core. Came along and requires at minimum Servlet 2.4 / JSP 2.0.
  • 1.2: exist of one JAR file jstl-1.2.jar and has same tagtlib URI as 1.1. Came along with Servlet 2.5 / JSP 2.0 but works at Servlet 2.4 / JSP 2.0 as well.

您可以通过使用zip工具提取JAR文件并阅读MANIFEST.MF文件来找到确切的JSTL版本.

You can find the exact JSTL version by extracting the JAR file with a zip tool and reading the MANIFEST.MF file.

Servlet/JSP版本取决于所使用的Web容器/应用程序服务器(甚至更多,它是Servlet/JSP实现),并且版本级别可在web.xml中进行配置.如果您至少使用Servlet 2.5/JSP 2.0实现(例如Tomcat 6.0),那么我建议您只选择JSTL 1.2.安装JSTL并不难:

The Servlet/JSP version depends on the webcontainer/application server used (even more, it is a Servlet/JSP implementation) and version level is configureable in web.xml. If you're using at least Servlet 2.5 / JSP 2.0 implementation such as Tomcat 6.0, then I'd recommend to just pick JSTL 1.2. Installing JSTL shouldn't be that hard:

  1. 放置 jstl-1.2. Webapp/WEB-INF/lib中的jar 文件.或使用Maven时:

  1. Place the jstl-1.2.jar file in Webapp/WEB-INF/lib. Or when you're using Maven:

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

  • 在JSP文件中用正确的TLD URI声明taglib.您可以在此处找到适用于两者的TLD文档JSTL 1.1和JSTL 1.2.单击感兴趣的taglib以获取声明示例.

  • Declare the taglib in JSP file with the right TLD URI. You can find here the TLD documentation which applies on both JSTL 1.1 and JSTL 1.2. Click the taglib of interest to get the declaration examples.

    确保在类路径(包括JRE/libAppserver/lib)中没有JSTL较旧版本的副本,以免发生冲突.如果您对应用程序服务器拥有完全的管理员级别控制权,则还可以将JAR文件放置在Appserver/lib中,而不是在Webapp/WEB-INF/lib中,以便将其应用到所有已部署的Web应用程序上.至少不要提取JAR文件并使类路径及其内容(松散的TLD文件)杂乱无章,和/或像一些不良的在线教程所建议的那样,在您的 webapp的web.xml中声明标签库.

    Ensure that you have no duplicates of older JSTL versions in the classpath (includes JRE/lib and Appserver/lib) to avoid collisions. If you have full admin-level control over the appserver, then you could also place the JAR file(s) in Appserver/lib instead of Webapp/WEB-INF/lib so that it get applied on all deployed webapps. At least do NOT extract the JAR file(s) and clutter the classpath with its contents (the loose TLD files) and/or declare the taglibs in your webapp's web.xml as some poor online tutorials suggests.

    web.xml中的servlet版本声明也影响JSTL的功能.通常的做法是将其声明为Web容器/应用服务器支持的最高值.在Servlet 3.0的情况下,web.xml应该如下所示:

    The servlet version declaration in web.xml has also incfluence on functioning of JSTL. Common practice is that you declare it to the highest which your webcontainer/appserver supports. In case of Servlet 3.0, the web.xml should look like:

    <?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">
    
        <!-- Config here. -->
    
    </web-app>
    

    确保其中没有<!DOCTYPE ...>,否则它将以Servlet 2.3兼容方式运行,然后EL表达式将停止工作.

    Make sure that you don't have a <!DOCTYPE ...> in there, otherwise it will run in Servlet 2.3 compatibility modus and then EL expressions will stop working.

    • Our JSTL wiki page
    • How to install JSTL? The absolute uri: http://java.sun.com/jstl/core cannot be resolved
    • EL expressions not evaluated in JSP

    这篇关于如何安装JSTL?绝对URI:无法解析http://java.sun.com/jsp/jstl/core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 05-27 21:57
    查看更多