This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on web.xml

 
Bhavna Jharbade
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

please help me to find the correct answer to the following:

1) Does the order of elements in web.xml matter??

2)<taglib> element comes directly under <web-app> or it�s a sub element of <jsp-config>?

Thanks
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Again,

1- yes, it does.(Take a look at the dtd file)

2- <taglib> under <jsp-config> - It's related to the old version of spec.
The new version of spec (for our exam) says that <taglib> is supposed to be under <web-app>.

Hope it help you!

cya!!
 
Bhavna Jharbade
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Felipe

Can u please send me the link for new specifications.

Or else u can mail them to me, my id is bhavna.0112@gmail.com

Thank you
 
Gab Buda
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bhavna, Felipe,

1) In servlet specs SRV.13.2 they say:
"The sub elements under web-app can be in an arbitrary order in this version of the specification."

2) The same pdf (servlet 2.4 spec) , lists on page 136 the child elements of <web-app> and there is no <taglib> (but there is a <jsp-config); instead, page 143: the <taglib> comes under the <jsp-config> element !

So if you have another references, Felipe, please argument...



Thank you
Gab

[ April 09, 2006: Message edited by: Gab Buda ]
[ April 09, 2006: Message edited by: Gab Buda ]
 
Bhavna Jharbade
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Felipe,Gab and others

I too found the things mentioned by Gab....but when I saw Felipe's response

I thought may be i have old specifications.

So Felipe please clear Gab and my doubt.

Thank you.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Gab is correct. The order of elements under the web.xml does not matter accroding to Servlet Spec 2.4. But the order of subelemnts under the main elements still important in this spec. That is, you can place <servlet> element anywhere in the web.xml. But <servlet-name> <servlet-class> should be in order.

The <taglib> element goes under <jsp-config>. But it is not required to declare taglibs using this tag as the container autosearch the .tld files in the directories specified in the spec.

Hope it help.

Thanks
 
Rodrigo Alvarez
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

(I'm new to this forum, this is my very first post,... soooo exited)

There are some cases when the order of web.xml elements influences the web app behaviors:

- listeners to servetContext,... are notified in the order in which they appear in the web.xml

- ServletFilters placed on a url-pattern process the (HttpServletRequest, HttpServletResponse) in the order in which the <filter-mapping> elements appears in the DD.

There are probably other examples.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There are some cases when the order of web.xml elements influences the web app behaviors:


Yes, the placement of listener,filters ordering is important, in which sequence they executed. But this is if the same element type, and the ordering is done as per your application needs. If you place there in arbitary order it will not be error, but your application logic may not work as you desire.

Thanks
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

Yes, you are dead right. The order doe snot matters. Tks.


Bhavna and Gab,

here: HFJ&S page 475.

"The OLD (before JSP 2.0)" ....

But actualy...now i got a bit confused too

Does it mean that we don't need to declared <taglib> anymore?
But is it mandatory don't declare that?
(sorry, have no time to test it now.)

Tks

Tks,
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, again...

i got this from the same page:

"The container will look first in your DD to see if you have made any <taglib> entries, and if you have, it will use those o help construct the map."

Tks.
 
Connie Ky Leung
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Felipe Pittella:
Hi, again...

i got this from the same page:

"The container will look first in your DD to see if you have made any <taglib> entries, and if you have, it will use those o help construct the map."

Tks.


<taglib> entry is not mandatory in web.xml but you can define one or more <tablib> entries if necessary.

The precedence of taglib map is specified in section of JSP 2.0 spec:

The following order of precedence applies (from highest to lowest) when building the taglib map (see the following sections for details):
1. Taglib Map in web.xml
2. Implicit Map Entries from TLDs
TLDs in JAR files in WEB-INF/lib
TLDs under WEB-INF
3. Implicit Map Entries from the Container

JSP.7.3.3 Taglib Map in web.xml
The web.xml file can include an explicit taglib map between URIs and TLD resource paths described using the taglib elements of the Web Application Deployment descriptor in WEB-INF/web.xml.

JSP.7.3.4 Implicit Map Entries from TLDs
The taglib map described in web.xml is extended with new entries extracted from TLD files in the Web Application.

JSP.7.3.5 Implicit Map Entries from the Container
The Container may also add additional entries to the taglib map. As in the previous case, the entries are only added for URIs that are not present in the map. Conceptually the entries correspond to TLD describing these tag libraries. These implicit map entries correspond to libraries that are known to the Container, who is responsible for providing their implementation, either through tag handlers, or via the mechanism described in Section JSP.7.3.9.

I only extract paragraphs that I think is important.
Hope this help.
 
Ernesto Leyva
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be it is container dependant
I remember I ran a test in Tomcat 5.5
I put taglib in DD just beneath
webapp and I do not remember getting
any error. But this is not guaranteed
since the spec says it should come under
jsp-config.
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, i got it, the <taglib> is not mandatory, because the container also utilizes its map object for retrieving the related tag libraries under WEB-INF/* and jar/META-INF/*.

But my questions is..(i got a little confused regarding <jsp-config> ..

Is "<web-app><jsp-config><tag-lib> " OLD evrsion right?
and for the exam the correct place for <taglib> would be "<web-app><taglib>" right?


Tks.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Originally posted by Felipe Pittella:
ok, i got it, the <taglib> is not mandatory, because the container also utilizes its map object for retrieving the related tag libraries under WEB-INF/* and jar/META-INF/*.

But my questions is..(i got a little confused regarding <jsp-config> ..

Is "<web-app><jsp-config><tag-lib> " OLD evrsion right?
and for the exam the correct place for <taglib> would be "<web-app><taglib>" right?


Tks.


Leung gave the detail explaination. The tomcat does not validate the web.xml for synthatic correctness. Accroding to the Servlet 2.4 the <taglib> must be placed under <jsp-config>. But it is optional.

If you want to check. Place the <uri> item in .tld with SomeName1 and define <taglib-uri> with SomeName2 in web.xml, like

<web-app ..>
....

<taglib>
<taglib-uri> SomeName2 </taglib-uri>
<latglib-location> your tld location </taglib-location>
</taglib>


Try to use the tag library using

<%@taglib prefix="mylib" uri="SomeName2" %> in JSP
<mylib:sometag />

It should not locate the required tag library, as it defined under <web-app>

It should work

<%@taglib prefix="mylib" uri="SomeName1" %> in JSP
<mylib:sometag />

As the containe bulid implicit map of tag libraries.

Hope this help

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic