aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Why doesnt eclipse generate a servlet mapping in web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Why doesnt eclipse generate a servlet mapping in web.xml" Watch "Why doesnt eclipse generate a servlet mapping in web.xml" New topic
Author

Why doesnt eclipse generate a servlet mapping in web.xml

Adam Zedan
Ranch Hand

Joined: Jun 10, 2011
Posts: 124

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
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

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).


JBoss In Action
Adam Zedan
Ranch Hand

Joined: Jun 10, 2011
Posts: 124

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

(c) Copyright Eclipse contributors and others 2005, 2011. All rights reserved.
Visit http://www.eclipse.org/webtools


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
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...

Hope that helps.
Adam Zedan
Ranch Hand

Joined: Jun 10, 2011
Posts: 124

i do tick that box after creating a dynamic website. still i dont get it. is there anyone else experiencing the same problem???
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

@Scott: welcome to Java Ranch!

@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
Ranch Hand

Joined: Jun 10, 2011
Posts: 124

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
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 ?
Mahendr Shinde
Ranch Hand

Joined: Sep 03, 2011
Posts: 38

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


There is still lot to learn!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10246
    
    8

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


Welcome to the Ranch!
Indeed. Annotations would be another way of defining the mappings. However, it might be noted that one would require JDK1.6 and a Servlet 3.0 compliant container like Tomcat7 and above. More information on servlet annotations here http://java.sun.com/javaee/6/docs/api/javax/servlet/annotation/package-summary.html#package_description


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why doesnt eclipse generate a servlet mapping in web.xml