This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to load servlet in Tomcat 5.5

 
Narasimha Sharma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You put the context root of your web app in ROOT. This is wrong. It belongs in webapps; ROOT is its own application.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17995
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Narasimha!
 
Narasimha Sharma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear !! It worked when I moved the folder to webapps rather than webapps->ROOT ..

Thanks Tom for the welcome !!
 
parni raghuvanshi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic