• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet not running

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to webdevelopment. I am using Tomcat 5 on Windows 2000. The examples that came with Tomcat works fine. I compiled my own servlet and when I try to run it I get a 404 error. Please help me on how I should configure Tomcat to run by servlet.
Regards,
Maru
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is a pretty sketchy description, but based on the observed probability of various errors made by new users, I would say that you have run into the "invoker" servlet problem. Take a look at the JavaRanch FAQ.
Bill
 
Mulugeta Maru
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am very sorry for not providing details to my problem. All the examples that cam with Tomcat work when used http://localhost:8080/servlet-examples/session.
I created my own servlet (a very simple one HelloWorld). I compiled and placed my servlet in a folder called mywebapp. When I use http://localhost:8080/mywebapp/HelloWorld I get 404 error. Since I am new to this area I thought there may be configuration issue I have to do to properly use Tomcat.
Regards,
Maru
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes there are configuration issues.
If you want Tomcat to recognize TOMCAT_HOME/webapps/mywebapp directory as a web application, then mywebapp directory must have a WEB-INF subdirectory which must have a web.xml file and a classes subdirectory. The web.xml file must define the mapping of your servlet class to the HelloWorld URL.
Furthermore, your servlet class should be in a package.
I consider it unfortunate that the Tomcat 5 distribution chooses to continue using the invoker servlet in the servlet-examples (check the web.xml for invoker) - it just makes things harder when folks try to set up their own web application because it takes the "invoker" shortcut.
Bill
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunate Tomcat 5 factoid #2:

Tomcat 5 example app uses pre-compiled JSPs. So if your JSP configuration is not happy either (say, JAVA_HOME is not properly set), you won't know about that either.

grrrrr.

And with Tomcat 5, they've commented not only the mapping, but the servlet declaration as well.
 
Mulugeta Maru
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You all are very helpful and I must say thank you. I followed your advice and did some reading. Yes it does work now. However, I am not sure how packaging works in a servlet set-up. Could you please give me a code example if at all possible.
Regards,
Maru
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The package situation is really very simple. In order to avoid really weird and hard to trace bugs, ALL classes used in servlets or jsp should be defined as being in packages. You have to observe the following conventions:
1. when placing the compiled class files under WEB-INF\classes the complete package directory has to be created. So my classes for my phonetic lookup example live in:
webapps\phonetic\WEB-INF\classes\com\wbrogden\phonetic
because the package statement is:
package com.wbrogden.phonetic ;
2. the declaration of servlets in web.xml must name the classes correctly as in this example:

3. when using JavaBeans in JSP, you have to give the complete package when declaring the bean, AND you have to import the package.
Bill
 
Mulugeta Maru
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Bill. I am learning as I go. I now understand the reason why using a package is a good idea. Why is it that the servlet-name "metaphone" different from the servlet-class "MetaphoneServ"?
I am lost on the following:
<init-param>
<param-name>listshome</param-name> <param-value>c:/Servers/Data/Phonetic</param-value></init-param>
What does c:/Servers/Data/Phonetic mean in this context? I thought you stored the servlet classes in web\phonetic\WEB-INF\classes\com\wbrogden\phonetic.
Thank you for your help and sorry for taking more of your time.
Regards,
Maru
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. My use of metaphone for the servlet name is purely arbitrary.
2. The init-param contents are used to pass configuration data to the servlet. In this case it is the directory on my hard drive where the wordlist files are kept. In the init() method of the servlet I grab that value to initialize the servlet data - like this:

where the locateHashmaps method uses the param-value matching the "listshome" param-name.
Bill
 
Mulugeta Maru
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for taking the time to help me. I need now to buy a book (hope to get a good book) to learn Servlet and JSP.
Regards,
Maru
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic