java 在 Apache tomcat7 中安装标签库时遇到问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10139500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 23:45:33  来源:igfitidea点击:

Getting trouble in installing tag lib in Apache tomcat7

javatomcatservletsjstl

提问by KSHiTiJ

I have application and I want to use jstl tag lib.

我有应用程序,我想使用jstl tag lib.

I have two jars JSTL.jarand standard.jar. I put both in my WEB-INF/libfolder.

我有两个罐子JSTL.jarstandard.jar。我把它们都放在我的WEB-INF/lib文件夹中。

I configure it in web.xmllike

web.xml像这样配置它

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

    <taglib>
        <taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
        <taglib-location>/WEB-INF/fmt.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
        <taglib-location>/WEB-INF/c.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
        <taglib-location>/WEB-INF/sql.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
        <taglib-location>/WEB-INF/x.tld</taglib-location>
    </taglib>

    <servlet>
        <servlet-name>loadingServlet</servlet-name>
        <servlet-class>loadingServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>loadingServlet</servlet-name>
        <url-pattern>/loadingServlet</url-pattern>
    </servlet-mapping>

     <welcome-file-list>
                <welcome-file>homepage.jsp</welcome-file>
    </welcome-file-list>

</web-app>

and on page i am using following code

在页面上我使用以下代码

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

and still i am getting error. like

我仍然收到错误。喜欢

    INFO: Deploying web application directory ServletExample
13 Apr, 2012 4:00:31 PM org.apache.tomcat.util.digester.Digester startElement
SEVERE: Begin event threw exception
java.lang.IllegalArgumentException: taglib definition not consistent with specification version
    at org.apache.catalina.startup.TaglibLocationRule.begin(WebRuleSet.java:1167)
    at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1282)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1359)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2747)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1543)
    at org.apache.catalina.startup.ContextConfig.parseWebXml(ContextConfig.java:1714)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1208)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:881)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:316)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5103)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:812)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:787)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:607)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1055)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:978)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:472)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1322)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
    at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:379)
    at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:324)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1041)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:620)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:303)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:431)
13 Apr, 2012 4:00:31 PM org.apache.catalina.startup.ContextConfig parseWebXml
SEVERE: Parse error in application web.xml file at jndi:/localhost/ServletExample/WEB-INF/web.xml
java.lang.IllegalArgumentException: taglib definition not consistent with specification version
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2687)
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2713)
    at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1285)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1359)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2747)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1543)
    at org.apache.catalina.startup.ContextConfig.parseWebXml(ContextConfig.java:1714)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1208)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:881)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:316)

回答by BalusC

You made several mistakes:

你犯了几个错误:

  • You should not manually redefine JAR's own taglibs in web.xml. This is a myth.
  • You should be using a Servlet 3.0 compatible web.xmlfor Tomcat 7.
  • You should be using JSTL 1.2, not 1.0.
  • 您不应该在web.xml. 这是一个神话。
  • 您应该使用与web.xmlTomcat 7兼容的 Servlet 3.0 。
  • 您应该使用 JSTL 1.2,而不是 1.0。

Remove them all. Remove all <taglib>from web.xml. Remove the both JARs from /WEB-INF/lib. Then follow the following steps:

将它们全部删除。删除所有<taglib>web.xml。从/WEB-INF/lib. 然后按照以下步骤操作:

  1. Download jstl-1.2.jarand drop it in /WEB-INF/lib.
  2. Fix your web.xmlto be Servlet 3.0 compatible.

    <?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. No taglibs! -->
    
    </web-app>
    
  3. Use the documentedtaglib declaration:

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    
  1. 下载jstl-1.2.jar并将其放入/WEB-INF/lib.
  2. 修复您的web.xmlServlet 3.0 兼容。

    <?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. No taglibs! -->
    
    </web-app>
    
  3. 使用记录在案的taglib 声明:

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

See also:

也可以看看:



I have a vague suspicion that you're using Roseindia.net as a Java EE resource. Your invalid approach is also mentioned in there. You should not do that. You should put that site in your Internet blacklist. This site is so full of bad answers and bad practices. Use Oracle's official resources instead, or Stackoverflow.com of course.

我模糊地怀疑您将 Roseindia.net 用作 Java EE 资源。那里也提到了您的无效方法。你不应该那样做。您应该将该站点放入您的 Internet 黑名单中。这个网站充满了糟糕的答案和糟糕的做法。改用 Oracle 的官方资源,或者当然是 Stackoverflow.com。

回答by jpllosa

If you are one of the lucky few that have to support old code and removing taglibin your web.xmlis not an option. You can enclose it in <jsp-config>like so:

如果您是少数必须支持旧代码的幸运儿之一,那么删除taglib您的代码web.xml是不可行的。你可以<jsp-config>像这样将它括起来:

<jsp-config>
  <taglib>
    <taglib-uri>/taglibs/custom-taglib</taglib-uri>
    <taglib-location>/WEB-INF/custom-taglib.tld</taglib-location>
  </taglib>
</jsp-config>

回答by Dave Newton

You don't need to configure taglibs in web.xml anymore. Plus you're defining different taglib urls (iirc the web.xml ones are correct).

您不再需要在 web.xml 中配置 taglibs。另外,您正在定义不同的 taglib url(iirc web.xml 是正确的)。

Use the uris from your web.xml in the jsp and remove the web.xml taglib defs.

在 jsp 中使用 web.xml 中的 uris 并删除 web.xml taglib defs。