5

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

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

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>

在页面上我使用以下代码

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

我仍然收到错误。像

    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)
4

3 回答 3

15

你犯了几个错误:

  • 您不应该在web.xml. 这是一个神话。
  • 您应该使用与web.xmlTomcat 7 兼容的 Servlet 3.0。
  • 您应该使用 JSTL 1.2,而不是 1.0。

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

  1. 下载jstl-1.2.jar并将其放入/WEB-INF/lib.
  2. 修复你web.xml的 Servlet 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" %>
    

也可以看看:


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

于 2012-04-13T12:13:58.740 回答
3

如果您是少数必须支持旧代码的幸运者之一,那么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>
于 2019-07-30T12:47:26.407 回答
0

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

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

于 2012-04-13T11:06:01.893 回答