GeeCON Prague 2014*
The moose likes Servlets and the fly likes servlet tags declared before servlet-mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet tags declared before servlet-mapping" Watch "servlet tags declared before servlet-mapping" New topic
Author

servlet tags declared before servlet-mapping

Angel J Gama
Ranch Hand

Joined: Jun 28, 2007
Posts: 36
Hi,
I was reading the Invoker Servlet FAQ and it says that:
...
The Middling Tale
...
Order of elements in web.xml is very important. So when you go to create your second 'couplet', make sure all your <servlet> tags are declared before your <servlet-mapping> tags. You'll maybe want to keep the 'couplets' together, because it will be easier to see which one belongs to which, but don't do it!

I've been writing the <servlet-mapping> tag just after its own <servlet> tag and I haven't had problems.
Does any one knows why don't keep 'couplets' together?
[ August 31, 2008: Message edited by: Angel J Gama ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

What version of servlets are you using? The order was relaxed for 2.4 which uses XML Schema rather than a DTD.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Angel J Gama
Ranch Hand

Joined: Jun 28, 2007
Posts: 36
I'm using servlet spec 2.5 (tomcat 6.x)...

would it be a good "practice/convention" to code <servlet> tags first, and then <servlet-mapping> tags?
Thanks
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

In practice it is easier to manage by coupling the servlet and servlet-mappings, as it is easier to manage if you end up with a large number of servlets ie it scales better.
 
GeeCON Prague 2014
 
subject: servlet tags declared before servlet-mapping