Java EE 7 : Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”

元气小坏坏 提交于 2019-12-08 09:19:41

问题


I am trying to use the following tag lib in my JSP page :

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

But Eclipse shows me this error :

Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"

I am already having JSTL in my classpath using this dependency :

<dependency>
  <artifactId>javaee-api</artifactId>
  <version>7.0</version>
  <scope>provided</scope>
</dependency>

I use WildFly 9.

I have the same problem with these 2 other taglibs :

<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>

Remark : The following link is giving 404 HTTP error : http://central.maven.org/maven2/javax/servlet/jsp/jstl/jstl/1.2/jstl-1.2.jar

Thank you.


回答1:


If your web application uses JSTL directly, for JSTL 1.0, the namespace is http://java.sun.com/jstl/core. In JavaEE 5, JSTL 1.1 is included, the namespace is http://java.sun.com/jsp/jstl/core. In JaveEE 6 and JavaEE 7, JSTL 1.2 is included, the namespace is http://java.sun.com/jsp/jstl/core.

But if your web application uses JSF+Facelets, for JSF 1.x+Facelets 1.x in JaveEE 5, the namespace is http://java.sun.com/jstl/core. For JSF 2.0+Facelets 2.x in JavaEE 6, the namespace is http://java.sun.com/jsp/jstl/core. For JSF 2.2+Facelets 2.2 in JavaEE 7, the namespace is http://xmlns.jcp.org/jsp/jstl/core.




回答2:


The Java EE 7 Tutorial briefly states the new URIs for JSTL in the What Is Facelets section as :

  • http://xmlns.jcp.org/jsp/jstl/core
  • http://xmlns.jcp.org/jsp/jstl/functions

However, I have yet to find an implementation of the taglibs that use the URI. So the URIs (with their recommended namespaces) should be defined as:

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

And to get rid of the error you need an implementation of the JSTL loaded as a dependency in provided scope e.g.

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

The provided scope prevents it from being included into the WAR file since the one being used by the application server should be used.



来源:https://stackoverflow.com/questions/34539301/java-ee-7-can-not-find-the-tag-library-descriptor-for-http-java-sun-com-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!