• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why doesnt eclipse generate a servlet mapping in web.xml

 
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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
Posts: 124
C++ Fedora Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ?
 
Ranch Hand
Posts: 38
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic