wood burning stoves 2.0*
The moose likes Servlets and the fly likes Beginner question about where to put servlet for application run under Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Beginner question about where to put servlet for application run under Tomcat" Watch "Beginner question about where to put servlet for application run under Tomcat" New topic
Author

Beginner question about where to put servlet for application run under Tomcat

Susan Smith
Ranch Hand

Joined: Oct 13, 2007
Posts: 224
Hi,

I'm trying to create my first servlet.

Let say my first application, I tried to put the .class file inside /apps/servlet then I tested the URL but I got HTTP 404 error.
I also tried putting it under /apps/WEB-INF/classes but it also gives me the same error.

I have Tomcat 5.5.23

Can someone please advise?

Thanks in advance for all the help.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Classes should go under /WEB-INF/classes, following package notation. So if the class is bar.baz.MyFirstServlet.class its directory location would be /WEB-INF/classes/bar/baz/MyFirstServlet.class.

The servlet also needs to be mapped, however; mere existence in the classpath isn't enough: for example, see http://javapapers.com/servlet/what-is-servlet-mapping/ or search the web for other examples.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61646
    
  67

Have you read the Servlet Specification? If not, do so before writing another single line of code.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Consider Paul's rocket mass heater.
 
subject: Beginner question about where to put servlet for application run under Tomcat