File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes servlet trouble.....   PLEASE HELP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet trouble.....   PLEASE HELP" Watch "servlet trouble.....   PLEASE HELP" New topic

servlet trouble..... PLEASE HELP

Alfonso Harding
Ranch Hand

Joined: Feb 09, 2002
Posts: 35
Can someone please tell me why my servlets dont work outside the webapps/example directory? I follow all the necessary steps but for some reason the servlets are not recognized. When I place them in the examples/WEB-INF dir, they work just fine. Please help.......
Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
have you tried searching the forum for this problems as I have personally seen the same question a number if times in the last few weeks alone.

The secret to creativity is knowing how to hide your sources.
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
There could be several issues, but most likely it's a configuration issue. If you want to use a different directory, you need to define a "context", which at a basic level maps to a subdirectory within "<home>/webapps". You can define this either in the main configuration file (<home>/conf/server.xml), or in a separate file that is placed in the "<home>/webapps" directory. Note that "<home>" refers to wherever Tomcat is installed. Also note that I'm assuming you are running Tomcat, which is usally a pretty good assumption ;-).
If you look in the "<home>/conf/server.xml" file you will see a section defined as:

This defines a "context" so that URL requests to "../examples/.." will be resolved by looking in the "examples" subdirectory within webapps.
You will need to create another context, using the "examples" context as a model. The new sub-directory will have to be set up (with a "WEB-INF" subdirectory, with a "web.xml" file, etc.) as well. It's all there in the documentation, just play around a bit and you should get it running.
Good luck.
[ September 08, 2003: Message edited by: Wayne L Johnson ]
Alfonso Harding
Ranch Hand

Joined: Feb 09, 2002
Posts: 35
thanks for the help Wayne.... I'll try it out.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
/examples/ works because the web.xml for the examples defines the invoker servlet - like Faisal said, this comes up all the time.
I agree. Here's the link:
subject: servlet trouble..... PLEASE HELP
jQuery in Action, 3rd edition