File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Deploymen Descriptor (web.xml) file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Deploymen Descriptor (web.xml) file" Watch "Deploymen Descriptor (web.xml) file" New topic
Author

Deploymen Descriptor (web.xml) file

Yogender Butola
Greenhorn

Joined: Jul 19, 2004
Posts: 12
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?

Pls Answer

Regards Yogi
"My mind works like lightining, one brilliant flash and it's gone."
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
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
Sanjeev Kaushik
Ranch Hand

Joined: Aug 01, 2002
Posts: 105
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


Sanjeev Kaushik
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Mark Stein
Ranch Hand

Joined: May 20, 2002
Posts: 75
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.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deploymen Descriptor (web.xml) file