Hi i wanted to know when we create a dynamic web project in eclipse and add a servlet why doesnt eclipse generate a servlet mapping in the web.xml on the other hand when we insert listeners or context data in our dynamic web project we have to put the entries in the web.xml manually. Servlet mapping is necessary so why dont we get an error if a servlet mapping is not found in web.xml.
This sounds too simple to be true but it might be it:
1. File>New>Project>Dynamic Web Project
2. After entering the name for your project DON'T CLICK FINISH, click next and next again to get to the "web module" window
3. Click the checkbox "generate web.xml deployment descriptor"
I have no idea why this doesn't just happen automatically when you just click finish...
@Adam: I have the same version of Eclipse, and did the same step as you did, and here is my web.xml:
I have no idea why it isn't working for you. You might check the log file (workspace/.metadata/.log) to see if there is any clue as to what went wrong.
Some other things to try:
a) Create a new workspace and a new dynamic web project, and a servlet, there.
b) Install another copy of Eclipse in another location and run it; have it create a new workspace and try again with the dynamic web project and servlet.
If "a" works, then your workspace/.metadata is screwed up. If "b" works then you Eclipse installation is screwed up. In either case you can copy your project directories from the old workspace to the new workspace and use File | Import | Existing Project to get them into your new workspace (and thus not loose any work).
Adam Zedan wrote:I finally found out what was wrong... the web project version that i am using is anotation based and switching to a lower version generated the mapping in web.xml.
I am new to Java.I was having the same problem , choosing a lower version of Dynamic Web Module version worked for me . But I could not understand what goes behind all this ?
What is Annotation based project ?
Besides , even if the web.xml is not updated (when we choose version Web Module Version3.0) the servlets are registered and they work . Then why cant we see that in web.xml ?
Annoted configuration helps you to directly define URL pattern for your servlet directly inside your ".java" file (yes i am right it's there in your source code!). so there will be NOTHING written inside "WEB.xml" about your servlet
Mahendr Shinde wrote:Annoted configuration helps you to directly define URL pattern for your servlet directly inside your ".java" file (yes i am right it's there in your source code!). so there will be NOTHING written inside "WEB.xml" about your servlet