File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Servlets not working under Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Servlets not working under Tomcat" Watch "Servlets not working under Tomcat" New topic
Author

Servlets not working under Tomcat

Michael Sullivan
Ranch Hand

Joined: Dec 26, 2003
Posts: 235
Okay, I did research on this, but alas I need another pair of eyes.
From this page: http://test.javaranch.com/wiki/view?InvokerServlet
In the file conf/web.xml find a section of text that looks like this:
<!-- The mapping for the invoker servlet -->
<!--
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>-->
You need to uncomment the servlet-mapping and then restart Tomcat to allow all servlets to work.

Yes, I know that this is a security risk, however since I'm going through a textbook that supplies code for many, many servlets... I don't want to add mapping for each of them since this isn't for production (or even development) but for training purposes. However I find myself in a bind-when I save HelloWorld.java and HelloWorld.class file to root/web-inf/classes and then try to call the servlet by:
http://localhost:8080/servlet/HelloWorld
I get the infamous: The requested resource (/servlet/HelloWorld) is not available.
so, what could be wrong? I should be correct in assuming that by uncommenting the servlet invoker that I should be able to type in: http://localhost ort/servlet/servletName and access the servlet, no?
I've been all over the Jakarta site, and to tell you the honest truth, Java Ranch is a lot more user friendly... which is how I ended up here (again).
I've even tried to place it in the servlets-examples directory, and modified the appropriate web-xml file with the following mapping:
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
and even this:
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>/servlet/HelloWorld</servlet-class>
</servlet>
But still, no love. Unfortunately, its too late at this hour to head out to the bookstore and reference one of the Sun Core JSP and Servlet texts, so I thought to ask here. Any ideas?
Thanks,
Michael
Michael Sullivan
Ranch Hand

Joined: Dec 26, 2003
Posts: 235
well, not sure what to make of this. Went to the bookstore and referenced a couple of texts that note that Tomcat is more difficult to config than the other servers. I tried mapping my servlets with no effect, and changed various server.xml and web.xml settings... also in vain.
I had previously downloaded Resin, and unzipped that, made one slight change to the server.xml file and presto! Servlets working fine. Strange.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
Tomcat seems simple to configure to me. It follows the published servlet API exactly.
It is the use of the invoker servlet that has led people astray many times - primarily because earlier versions had it on by default and the introductory books used it.
If you are using the invoker servlet, you don't need to define anything in web.xml but the invoker - just make sure your class files end up in the right place.
Bill
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Servlets not working under Tomcat
 
Similar Threads
404 Error...need help
Change in servlet-class & servlet-name in web.xml not reflected? Why?
Tomcat 6.0.26 & IIS 7.0 - 404 - File or directory not found
Servlet filter not getting invoked
trouble loading servlet class on Tomcat4.1.24