Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet tags declared before servlet-mapping" Watch "servlet tags declared before servlet-mapping" New topic

servlet tags declared before servlet-mapping

Angel J Gama
Ranch Hand

Joined: Jun 28, 2007
Posts: 36
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

Joined: Jan 10, 2002
Posts: 60739

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?
David O'Meara

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.
It is sorta covered in the JavaRanch Style Guide.
subject: servlet tags declared before servlet-mapping
Similar Threads
Cant read config params in JSP
Order of elements in DD and servlet/servlet-mapping
access a servlet usin its name
url-pattern example
RequestDispatcher problem