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.
Don’t look where you fall, but where you slipped
Peter Johnson wrote:Which version of Eclipse are you running? Helios (3.5) creates servlet and servlet-mapping entries in web.xml when you create a servlet.
Also, I assume you are using File | New | Servlet to create a servlet (that is, you are not doing File | New | Class).
Right click on project >> new >> servlet
in the new window :
Java Package: com.checkservlet
Class name: checkservlet
Super class :javax.servlet.http.HttpServlet click Finish
Now Double Click on Deployment Descriptor we get web.xml which contains
Notice there wont be a trace a new servlet
I am using:
About Eclipse:
Eclipse Java EE IDE for Web Developers.
Version: Helios Service Release 2
Build id: 20110218-0911
Any suggestions... The servlets work and my jsps post to them ok.. so where can i see the servlets being registered
Scott Robinson
Greenhorn
Joined: Jun 30, 2011
Posts: 1
posted
0
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).
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.
Ankit Tripper
Greenhorn
Joined: Aug 13, 2011
Posts: 5
posted
0
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