File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Getting started with Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting started with Servlets" Watch "Getting started with Servlets" New topic
Author

Getting started with Servlets

Michael Zellmann
Greenhorn

Joined: Dec 17, 2004
Posts: 18
I am having trouble getting started with my own Servlets on my own Tomcat installation. I can get the Tomcat Welcome Page, the Tomcat Manager page and the examples that come with the Tomcat distribution, but if I try do some simple examples from any of the books, for instance Head First Servlets & JSP, I get resource not found.

Specifically
http://localhost:8080/ch1/Serv1
produces
HTTP Status 404
The requested resource (/ch1/Serv1) is not available.

Some specifics.
I have Tomcat 5.5
Here is my implementation of the very first example in Head First.
I deployed this without using a .war
This is the structure under webapps
ch1/
WEB-INF/
web.xml classes/
Ch1Servlet.class


my java class:

Here is my web.xml

I haven't done anything to the Tomcat setup. I believe the server is correctly set-up to deploy .wars Here is the section of the server.xml

I also tried the "SimpleServlet" example offered from a link on the forum page http://simple.souther.us/index.html

The Tomcat Manager shows that for the ch1 and SimpleSrevlet Running is false

I have gone over every aspect I could think of and I am obviously missing something basic.

Any help will be appreciated.
[ February 21, 2007: Message edited by: Michael Zellmann ]
Joan Horta Tosas
Ranch Hand

Joined: Feb 01, 2007
Posts: 59
At least in JBoss you have to include the extension .WAR to the directory you want to use as an exploded web-app. Don't know if it's the same in Tomcat standalone, but JBoss uses Tomcat... So try it. Rename ch1 dir to ch1.WAR
Pablo M´┐Żller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
You don't need the .war extension with tomcat.
For what I see your servlet is in the default package.. If it's not, you have to write the fully qualified name of the servlet class in the web.xml.
Pablo.


2B || !2B
Michael Zellmann
Greenhorn

Joined: Dec 17, 2004
Posts: 18
Thanks for the replies. I did try ch1.war, but to no avail. The ch1 directory is automatically generated when I drop the ch1.war into my webapps directory, so I think it is correct for Tomcat. You are also right that my Servlet is in the default package. I did that just to help make sure I wasn't mis-entering the qualified name. Still no luck.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60058
    
  65

Originally posted by Michael Zellmann:

The Tomcat Manager shows that for the ch1 and SimpleSrevlet Running is false


That means your web app hasn't started. No amount of standing on your head is going to make the servlet respond if the app isn't running.

You need to find out why the app won't start.

Anything interesting in the logs?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60058
    
  65

P.S. Please use UBB code tags when posting code. Read this for more info.
Michael Zellmann
Greenhorn

Joined: Dec 17, 2004
Posts: 18
Thanks for the replies. Now I understand the code tag and will use that in the future. I figured out the problems (by looking through the logs !) Tomcat logs hadn't been saying anything about my ch1 deployment and everything else that I expected to work was working, so I didn't read the entire log. It turns out that another app that I had tried to deploy didn't work, and it was still in webapps. Apparaently, everytime Tomcat would be started, it would load the other applications (from the Tomcat distribution), but when it got to my problem app, it had an exception because of missing class files. As a consequence, it "skipped inmstalling application listeners because of previous error(s)" I guess that meant it wouldn't pay attention to the ch1 deployment. I successfully deployed ch1 on my Glassfish, and on my public ISP, so I knew it worked. When I removed the other incorrect application from webvapps and Tomcat was able to start without exception, then ch1 worked fine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting started with Servlets
 
Similar Threads
Servlet is not running
Head First Servlets and JSP - My first servlet Program is not running
new to tomcat
404 Error
HTTP Status 404 The requested resource () is not available