aspose file tools*
The moose likes Tomcat and the fly likes Unable to load servlet in Tomcat 5.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Unable to load servlet in Tomcat 5.5" Watch "Unable to load servlet in Tomcat 5.5" New topic
Author

Unable to load servlet in Tomcat 5.5

Narasimha Sharma
Greenhorn

Joined: Jul 04, 2011
Posts: 6
Hi...

I'm using tomcat 5.5 for the first time. I have a jdk6 installed in my system. When I try to deploy a servlet, it is not getting picked up in the browser.

I have created a directory structure like this

WebApps
|
|
V
ROOT
|
|
---Sample
|
|
---index.html
|
WEB-INF
|
---web.xml
|
classes
|
----HelloServlet.class




This is a copy of my web.xml :

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>

<servlet>
<servlet-name>myHello</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>myHello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>

</web-app>


Link Tag my index.html :

<A HREF="hello">Run HelloServlet</A>


I get this error when I click the "Run HelloServlet" link :

HTTP Status 404 - /Sample/hello

type Status report

message /ch1/hello

description The requested resource (/ch1/hello) is not available.
Apache Tomcat/5.5.33


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

You put the context root of your web app in ROOT. This is wrong. It belongs in webapps; ROOT is its own application.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
Also classic error:


All classes used in servlets must be defined in packages and the compiled class file stored appropriately. Reason being that the JVM looks in the "current" directory for default package classes and you have NO control over the current directory with servlets.

See also FAQ on the dreaded Invoker servlet.

Bill
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16141
    
  21

Welcome to the JavaRanch, Narasimha!


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

Joined: Jul 04, 2011
Posts: 6
Thanks Bear !! It worked when I moved the folder to webapps rather than webapps->ROOT ..

Thanks Tom for the welcome !!
parni raghuvanshi
Greenhorn

Joined: Jun 21, 2011
Posts: 14
hello sir,previously i was using eclipse but it did not work good,so i suggest to install tomcat server & work in notepad but i do not know why tomcat server is not running,after installing tomcat when i click on the start an icon named "monitor tomcat" is seen ,when i click on it a message was encountered "access is denied unable to open the service tomcat 6.0".I downloaded it many times but same problem got occured.can you help me & give some suggestions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to load servlet in Tomcat 5.5