You DON'T have to define every servlet in the web.xml file. This definition is needed only :
1. If inside the servlet class you use some logic to use the ServletConfig.getInitParameter(), which has to get the init-param from the web.xml file.
2. If you don't want to call the servlet by its complete package hierarchy and want to give it a short name. This you do inside the <servlet> .. </servlet> element.
3. If you want to override the calling url-pattern. This you do inside the <servlet-mapping> .. </servlet-mapping> element.
For example, I have a servlet class file "HelloHttp.class" in the webapps/docroot/WEB-INF/classes/mypkg directory. I can access it by
http://localhost:8080/docroot/servlet/mypkg.HelloHttp without even defining it in the web.xml file.
However, if I'm calling it this way, then the ServletConfig.getInitParameter() will return null.
If I take the trouble and define it in the web.xml file as
<servlet>
<servlet-name> someservlet </servlet-name>
<servlet-class> mypkg.HelloHttp </servlet-class>
<init-param>
<param-name>somename</param-name>
<param-value>30</param-value>
</init-param>
</servlet>
then I will be able to call this servlet as
http://localhost:8080/docroot/servlet/someservlet and getInitParameter() will return 30.
However again, calling the same servlet as
http://localhost:8080/docroot/servlet/mypkg.HelloHttp will result in getInitParameter() returning null (Since the ServletConfig is not getting used here).
I hope this is clear.
Thanks, Sudd