First of all I'm new to all this stuff of servlets and JSP.
I want to Know one thing, that why do we use the dployment descriptor. I know that it is used to tell the container about our web component and services it require from the container. I've used Sun's J2EE 1.4 application server, which automatically generates a deployment descriptor for your component. But,I've also used Tomcat 4.0 and I havn't worked on the "web.xml" file still all my applicaions are working very well. For example, I've a shopping cart application in which I've used servlets for processing requests and JSP's for displaying the information. I've transferred requests, exception, and data from servlets to JSP's, but I haven't set a single mapping property or any thing in the "web.xml" file.
Now I'm confused!!! Is it necessary to work on "web.xml" file. If yes then why my applicaions are working well. If no then why you all people give your answer that relate to the "web.xml" file. Like settings related to mapping servlets when you are forwarding request from one servlet to a JSP page?
Regards Yogi "My mind works like lightining, one brilliant flash and it's gone."
No, it's not really neccesary to use web.xml if you are just working on simple servlets and JSPs. But if you want to package your applicatioin as a web application, especially if it needs to be distributed, you will definitely need to have an associated web.xml. It's always a good idea to make your servlets/JSPs part of a web application anyway.
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Its totally depends upon your programming practices and size of your application. Take an example: if your application has to make a data base connection, where from you will take URL, user id and password of DB. Either you have to hardcode in java class or you will read it from some file. If you hard code in java that is not a good programming practice. If due to some reason DB server is changed, then you have do the programming changes, recompilation, redeployment, etc. If you are reading from some file, you are doing something which servlet container already does for you. You can put these parameters in web.xml and container reads these parameters and pass to servlet while doing the initialization. This is just an example of one of the element in web.xml.
If you are developing a big application which contains multiple servlets, jsps, error pages, static html then you will see the need of web.xml
Ok, I am confused. If you have a JSP with a form like:
How does the container know where/what someServlet is without providing a mapping to the class in the web.xml file? I have never heard of not using the web.xml unless you are dealing with JSP only and no Servlets.
Originally posted by Mark Stein: Gregg, using Tomcat's invoker mapping (no longer a default in Tomcat) you can get to a servlet by /servlet/packagename.classname (Works in Resin too).
It's useful for testing, but I wouldn't want to use it in production use.
Good to know, but yeah, I can't see how that would be a good thing to use in production. Truly, I don't see how that is good for debugging either. It seems like it would be easier to just look at the web.xml mapping to figure out where things are going. But that is probably because I have always used the web.xml.