0

Name Mapping for Servlets ... Why three names???

Posted by Guillermo GarcĂ­a on 11:38 AM in , ,
Yeap, every servlet has three names:
  • The File Name: This is the name of the class file that implements the "controller logic" of the servlet. This name is the well know "Fully Qualified Name" of the class. Example: "com.ggarcia.java.ClassName".
  • The Internal Name: this is the name the deployer gives to the servlet in the deployment descriptor, aka DD, aka web.xml. The deployer could use any name, without any restriction (maybe a size limitation or special character limitation for non utf-8 compliant servers).
  • The Client Name: the name that the regular user will request in a browser. In a more technical lingo, is the URL of the servlet.
Then, why so many names? Well, if you know something about the JEE platform, maybe you have already read something about "roles responsabilities", one of the most important benefits of using this platform. Well, let's talk about roles. Simplifiying, there are at least, three roles involved in any web application development:
  • Developers: Exploited people making with their bare hands all the servlets, filters, tags libraries, java classes, etc. They define the "File Name" of the servlets.
  • Deployers: People losing all their energy working on the web container configuration. They love working late and they need to make changes all the time. So they use the "Internal Name" of the servlets for configuration, and if any developer changes a servlets "File Name" or creates a new one to replace an old one, the deployer only has to change the Servlet mapping, and that's it.
  • Users: How can we protected the user from this bunch of madmen? Well, the deployer creates a "Client Name", an URL for each "Internal Name" that the deployer knows. With this, the deployer feels free to work late at night without affecting any of the clients.

NOTE: Take a look at this web.xml example that uses the three names for a servlet (Image)

Obviously, the first benefit of this approach is flexibility. But, as always, when you choose a path, you lose another. If you aren´t careful enough, the Servlet Mapping could be a real mess. I recommend defining a name convention at the beggining of the project and having a very good communication mecanism between the role groups (with SVN and a ticket system like Bugzilla or OTRS).

0 Comments

Copyright © 2009 ggarciao.com
- Cup of Java -
All rights reserved.