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
Getting trouble in installing tag lib in Apache tomcat7
提问by KSHiTiJ
I have application and I want to use jstl tag lib
.
我有应用程序,我想使用jstl tag lib
.
I have two jars JSTL.jar
and standard.jar
. I put both in my WEB-INF/lib
folder.
我有两个罐子JSTL.jar
和standard.jar
。我把它们都放在我的WEB-INF/lib
文件夹中。
I configure it in web.xml
like
我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.xml
for Tomcat 7. - You should be using JSTL 1.2, not 1.0.
- 您不应该在
web.xml
. 这是一个神话。 - 您应该使用与
web.xml
Tomcat 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
. 然后按照以下步骤操作:
- Download jstl-1.2.jarand drop it in
/WEB-INF/lib
. Fix your
web.xml
to 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>
Use the documentedtaglib declaration:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
- 下载jstl-1.2.jar并将其放入
/WEB-INF/lib
. 修复您的
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>
使用记录在案的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 taglib
in your web.xml
is 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。