wood burning stoves 2.0*
The moose likes Servlets and the fly likes Simple Servlet problem 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 » Java » Servlets
Bookmark "Simple Servlet problem" Watch "Simple Servlet problem" New topic
Author

Simple Servlet problem

John R Roberts
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
Hi, I have created a simple servlet and was able to deploy it to the Tomcat examples folder. Modified web.xml to contain the servlet and servlet-mapping tags for my HelloWorld servlet. I wanted to deploy it into another directoy so at the same level as examples forlder in Tomcat I created a folder called test and placed a web.xml plus the classes into that folder. The directory structure for my demo folder is

demo
---WEB-INF
----classes
web.xml

in my web.xml I have
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/servlet/HelloServlet</url-pattern>
</servlet-mapping>

but I cannot get to the servlet, I keep getting a HTTP 404, the requested resource (demo/servlet/HelloServlet) is not available.
the URL I am entering is http://localhost:8080/demo/servlet/HelloServlet

can anyone help??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41085
    
  43
Is the HelloServlet class part of a package named "servlet"? If not, leave out the "servlet" from the URL and mapping.

In general you should avoid URLs that start with "servlet", because that looks like you might be using the InvokerServlet, which is not a good idea for the reasons explained on that page.


Ping & DNS - my free Android networking tools app
John R Roberts
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
I tried that and still I get a HTTP 404 error The requested resource (/HelloServlet) is not available.

Im a bit stumped as it works fine in the examples directory.
I must be doing something really stupid...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
Im a bit stumped as it works fine in the examples directory.

Probably the web.xml for your example folder has the "invoker" servlet turned on. The invoker is able to look for servlet classes that are not in a formal package (the "default" package).

However, the normal JVM class loader can NOT cope with this. ALL classes used in servlets should be put in a package. Trust me - this forum is littered with threads where people found this out the hard way.

Your web.xml would then give a complete package for servlet-class and the compiled class would be located accordingly under WEB-INF/classes

More about the Invoker and how it leads programmers astray (same link as Ulf quoted.)

Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60773
    
  65

Is your web.xml in the WEB-INF folder? Your diagram seems to indicate not.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John R Roberts
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
yes it is. I got it working in the end by just steping through the example line by line. thanks for all the help...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Simple Servlet problem
 
Similar Threads
Difficulties with setting up Apache tomcat: 'Need a little help.
Simple HelloServlet not working
Tomcat 4.0.1 - Servlet not found
web.xml andf default webapplication folder
Servlet Not working