You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Joseph Dane <jo...@hotu.com> on 2000/06/07 01:51:04 UTC
web.xml ordering
Greetings tomcatters -
Have recently begun experimenting with taglibs. Documentation is
thin, at best, but I thought I was setting things up correctly.
However, at access time for a test page which used the taglib, I got
an exception which looked something like this:
org.apache.jasper.JasperException: Parse Error in the tag library descriptor: Element "web-app" does not allow "servlet" here.
at org.apache.jasper.compiler.JspUtil.parseXMLDoc(JspUtil.java:157)
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:172)
at org.apache.jasper.compiler.JspParseEventListener.handleDirective(JspParseEventListener.java:665)
at org.apache.jasper.compiler.DelegatingListener.handleDirective(DelegatingListener.java:116)
at org.apache.jasper.compiler.Parser$Directive.accept(Parser.java:215)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1073)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1038)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1034)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:182)
and so on. The message seemed totally out of place, and I assumed it
was spurious somehow. After all, "web-app" is only specified in my
web.xml file, and tomcat had never complained about that before.
Further investigation revealed that the message was not so out of
place. The "parseXMLDoc" method in JspUtil creates a validating
parser for the web.xml file. I found that what the parser seemed not
to like was that my web.xml file mixed <servlet> and <servlet-mapping>
tags, as
<servlet>
<servlet-name>svt1</servlet-name>
<servlet-class>ServletOne</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>svt1</servlet-name>
<url-pattern>/foo.html</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>svt2</servlet-name>
<servlet-class>ServletTwo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>svt2</servlet-name>
<url-pattern>/bar.html</url-pattern>
</servlet-mapping>
After changing web.xml so that all <servlet-mapping> tags followed all
<servlet> tags, the taglib stuff worked perfectly.
I suppose my question is this: is this behavior expected? I am not an
XML expert, but I would have thought that tag ordering was
irrelevant. The DTD grammar, as far as I can read it, could be
interpreted as imposing such an ordering, but it still surprises me.
And, why should the JSP code use a validating parser when (apparently)
the rest of tomcat does not?
Also, the message in the exception quoted above is misleading: the
parse error was generated from the deployment descriptor, not from the
TLD.
Thanks,
--
joe