wood burning stoves*
The moose likes IDEs, Version Control and other tools and the fly likes Eclipse web.xml servlet mapping? 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 "Eclipse web.xml servlet mapping?" Watch "Eclipse web.xml servlet mapping?" New topic
Author

Eclipse web.xml servlet mapping?

nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
Hi, I am working with eclipse and i made a HelloWorld servlet and it run properly.
I know that when you make a servlet you must configure a web.xml file to map the servlet to a url but
i was searching to find the web.xml in eclipse that maps the servlet url but nothing. Where is it?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Please be sure to ask IDE questions in the IDEs forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

For my web apps, the file is always located at src/main/webapp/WEB-INF/web.xml, but then I use m2eclipse to create my projects. What are you using to create your web app projects?


JBoss In Action
nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
Sorry but i don't understand what m2eclipse is?
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

http://m2eclipse.sonatype.org/
nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
I AM NOT USING ANYTHING EXTRA. I JUST INSTALLED THE ECLIPSE 6.9 AND TOMCAT 7 AND STARTED WORKING.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10265
    
168

nick tomer wrote:I AM NOT USING ANYTHING EXTRA. I JUST INSTALLED THE ECLIPSE 6.9 AND TOMCAT 7 AND STARTED WORKING.


Please do not post in all caps. It's equivalent to shouting and is considered rude.


[My Blog] [JavaRanch Journal]
nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
i didn't knew that. sorry
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10265
    
168

i was searching to find the web.xml in eclipse that maps the servlet url but nothing. Where is it?


"Ctrl + Shift + R" in Eclipse will open a window where you can type the resource you are searching for (web.xml in this case).
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

nick tomer wrote:I AM NOT USING ANYTHING EXTRA. I JUST INSTALLED THE ECLIPSE 6.9 AND TOMCAT 7 AND STARTED WORKING.

Eclipse 6.9?
AFAIK, Eclipse now at version 3.6 .
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

I may be wrong but I think web.xml isn't required for JEE 6 (Tomcat 7 implements JEE 6) and maybe that is why he can't locate web.xml.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10265
    
168

John Todd wrote:I may be wrong but I think web.xml isn't required for JEE 6 (Tomcat 7 implements JEE 6) and maybe that is way he can't locate web.xml.


That's a good point. web.xml is indeed optional in Java EE 6. So it actually boils down to what URL nick used to test his application and which servlet (if any) got invoked.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16246
    
  21

There is no "web.xml in Eclipse". The web.xml file is in the J2EE WAR in the WEB-INF directory. Yes, JEE allows it to be be omitted or minimized in a lot of cases, but Eclipse has no inherent J2EE/JEE capabilities to begin with (they're supplied via Eclipse pug-ins), and in any event, a compliant J2EE/JEE app cannot be dependent on an IDE. Just because you develop it using an IDE and test it using an IDE, doesn't mean that the actual webapp is allowed to omit critical WAR elements when the spec demands them.


Customer surveys are for companies who didn't pay proper attention to begin with.
nick tomer
Greenhorn

Joined: Oct 18, 2010
Posts: 26
thanks a lot.

p.s. indeed, eclipse version is 3.6. i mixed up with netbeans.
Marcelo Yamashita
Greenhorn

Joined: Feb 08, 2006
Posts: 2
For some reason I got the same problem here.
I dont have any web.xml file in an EJB project that has a websercive running.

Its actually a problem, because every tutorial for securing web services strives for changes in the web.xml file. And i dont have one.

I know that this is kind of 'other post', but ..

.. how can I secure a webservice (authentication/authorization) without a web.xml file?


[] in advance.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16246
    
  21

Welcome to the JavaRanch, Marcelo!

This isn't quite the same topic as the original question, so it would have been better to start a new thread. But, since we've raised it from the dead, might as well continue!

JEE (not J2EE) allows the concept of "not having web.xml". Like JSF2, it does this by allowing the default definitions for values to be declared as annotations to the java source code.

Without actually reading the manual I seem to recall that there's an annotation that can allow you to put security controls on certain web resources via annotations, but I don't think that the master controls can be done that way. By "master controls", I mean global things like security transport mechanism selected, whether to use BASIC or form-based authentication and role name definitions. So you probably still need a minimal web.xml file to contain those things.

In J2EE, web.xml is mandatory, since the annotation support didn't exist back then. Note that for legacy EJBs, however, the EJBs had their own config files as well.
Nani Marni
Greenhorn

Joined: Aug 20, 2012
Posts: 1
You will get web.xml file by creating project like this in eclipse:-
File->New->Dynamic Web Project->Next->Next->Generate web.xml deployment descriptor(Select this check box)
then you will find the web.xml file under WebContent/WEB-INF
shaileshkumar mistry
Greenhorn

Joined: Dec 19, 2011
Posts: 19
Hi nick


you might be using annotations. if you are using annotations to map the url the entry wont be there in web.xml
Please check on top of servlet. you are finding syntax like

@WebServlet("/yourservlet");


Thanks and Regards

OCPJP 100%
Brandon Ke
Greenhorn

Joined: Jun 14, 2013
Posts: 1
nick tomer wrote:Hi, I am working with eclipse and i made a HelloWorld servlet and it run properly.
I know that when you make a servlet you must configure a web.xml file to map the servlet to a url but
i was searching to find the web.xml in eclipse that maps the servlet url but nothing. Where is it?


So I realize I am just shy of 3 years late to this party but in the event that anyone else stumbles upon this thread and needs a solution:

I am using Eclipse for JEE Developers (Helios) and deploying to a remote Glassfish Server running on a Linux box. The web.xml file will appear in the management console of the Glassfish server under the deployed .war program, but by default it doesn't show up in your Eclipse project's hierarchy. To generate this in Eclipse try this: Right-Click on your project -> go to 'Java EE Tools' -> and select 'Generate Deployment Descriptor Stub'. At this point you should see the "web.xml" file appear inside your "WebContent/WEB-INF/ " directory. Hope this helps.
 
 
subject: Eclipse web.xml servlet mapping?