Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes servlet-mapping tag in web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "servlet-mapping tag in web.xml" Watch "servlet-mapping tag in web.xml" New topic

servlet-mapping tag in web.xml

Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

I have a question about the servlet mapping tag.

Does each <servlet-name>, <url-pattern> mapped pair have to be in it's own servlet-mapping root?

i.e., if I have this scenario:-

Can I write is as the following?

"A problem well stated is a problem half solved.” - Charles F. Kettering
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper

Joined: Apr 07, 2010
Posts: 2102

Hi Nidhi,

Good question: you can't.

Have a look at Servlet 2.4 spec (SRV.13.4 Deployment Descriptor Diagram)
You will find nice diagrams explaining all the elements of the DD


Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

If the latter form is the case, its tough to form the <servlet-name> and <url-pattern> pair since there is one parent <servlet-mapping> node... And when you write a XML parser for this, you will get list of <servlet-names> nodes and <url-pattern> nodes not knowing which forms which pair...

So, to ease up, the former standard is used.... In this case, you will get the list of <servlet-mapping> nodes which contains <servlet-name> and <url-pattern> pair and no confusion of mapping it... Thats why

SCJP 6 [SCJP - Old is Gold]
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

Thanks Ram. So the parent <servlet-mapping> node is what ties the pair together. That's interesting.
Frits, the diagrams look quite helpful. Thanks for sharing.
I agree. Here's the link:
subject: servlet-mapping tag in web.xml
jQuery in Action, 3rd edition