I am fairly new, but perhaps I can help...

> -----Original Message-----
> From: Jim Cobban [mailto:[EMAIL PROTECTED]]
> Sent: Monday, March 18, 2002 10:34 AM
> To: Tomcat Users List
> Subject: Re: Urgent Re: Newbie: Servlet under Windows does not run
> 
> ----- Original Message -----
> From: "Wagoner, Mark" <[EMAIL PROTECTED]>
> Subject: RE: Urgent Re: Newbie: Servlet under Windows does not run
> 
> 
> > What URL are you using to get to the servlet?
> 
> I have tried a very wide range of URLs.  According to all of the
> documentation the one that should work is
> http://localhost/servlet/Census.CensusQuery  That is using the class
> name.
> However when that failed I also tried  /servlet/Census/CensusQuery,
> and  /servlet/CensusQuery.  Since in my web.xml file, which I posted
> earlier, the name of the servlet, as opposed to the class, was
> Census1901 I
> also tried /servlet/Census1901.  I have also tried using URL mapping
> specified in the
> WEB-INF/web.xml file.  In any event the bottom lime is that when I
> request
> the above URL TomCat does go looking for my class.  It just can't seem
> to
> find it!
> 
> I know that I must be doing something wrong, because nobody else seems
> to be
> having any difficulty running servlets, but this is driving me crazy.
> I
> have been trying everything I can think of for more than a week and
> TomCat
> keeps claiming that it can't find the class.  I have read the
> documentation
> over and over again.  I have gone with a fine tooth comb through the
> examples trying to see what they are doing that is different from what
> I am
> doing.  I just don't understand why this is so bloody difficulty.
> 
> Just to put every bit of the documentation of this problem in one
> place:
> 
> The first few lines of my servlet are:
> 
> package Census;

OK. First, you should use the naming convention of having your packages
lowercase. A little known fact is that classes and packages share the
same namespace, so you risk a collision. (You don't have any classes or
interfaces called Census do you???)
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.sql.*;
> public class CensusQuery extends HttpServlet {
> 
> 
> which I compile using the following .bat file:
> 
> set PATH=C:\jdk1.3.1\bin;%PATH%
> set
> CP=D:\jakarta-tomcat-3.3a\lib\common\servlet.jar;WEB-

I'm surprised this works since servlet.jar is in common/lib (at least in
the 4.0.3 release)

> INF\classes;%CLASSPATH%

This is dangerous. I notice you are doing db stuff. You wouldn't happen
to be doing a Class.forName would you? If you are, then your servlet
won't run without your JDBC driver in web-inf/lib.

>  javac -d WEB-INF/classes -classpath %CP% ConnectionPool.java | more
>  javac -d WEB-INF/classes -classpath %CP% DBResults.java | more
>  javac -d WEB-INF/classes -classpath %CP% DriverUtilities.java | more
>  javac -d WEB-INF/classes -classpath %CP% DatabaseUtilities.java |
> more
>  javac -d WEB-INF/classes -classpath %CP% ServletUtilities.java | more
>  javac -d WEB-INF/classes -classpath %CP% CensusQuery.java | more

> jar cf Census.war *.html WEB-INF

It seems like you are compiling a lot of stuff here. Is this your first
servlet? Have you ever successfully gotten a simple servlet to run? I
would recommend doing that first. That said...

Also, tomcat does not require that you use a war file, and I suggest
that you don't, especially for development. Also, tomcat will use the
default context of "Census" - possibly confusing itself and you.
> 
> 
> The .war file this produces contains:
> 
> D:\MyPrograms\JavaProgs\CensusServlet>jar -tf Census.war
> META-INF/
> META-INF/MANIFEST.MF
> CensusQuery.html
> WEB-INF/
> WEB-INF/classes/
> WEB-INF/classes/Census/
> WEB-INF/classes/Census/ConnectionPool.class
> WEB-INF/classes/Census/DBResults.class
> WEB-INF/classes/Census/DriverUtilities.class
> WEB-INF/classes/Census/DatabaseUtilities.class
> WEB-INF/classes/Census/ServletUtilities.class
> WEB-INF/classes/Census/CensusQuery.class
> WEB-INF/web.xml
> 
> The web.xml file is:
> 
> <?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>
>     <display-name>My Web Application</display-name>
>     <description>
>       This is version X.X of an application to perform
>       a wild and wonderful task, based on servlets and
>       JSP pages.  It was written by Dave Developer
>       ([EMAIL PROTECTED]), who should be contacted for
>       more information.
>     </description>
> 
>     <servlet>
>         <servlet-name>
>             Census1901
>         </servlet-name>
>         <servlet-class>
>             Census.CensusQuery
>         </servlet-class>
> 
>         <init-param>
>             <param-name>DbVendor</param-name>
>      <param-value>mysql</param-value>
>         </init-param>
>         <init-param>
>      <param-name>Url</param-name>
>      <param-value>localhost</param-value>
>         </init-param>
>         <init-param>
>      <param-name>DbName</param-name>
>      <param-value>Census</param-value>
>         </init-param>
>         <init-param>
>      <param-name>UserName</param-name>
>      <param-value>anonymous</param-value>
>         </init-param>
>         <init-param>
>      <param-name>Password</param-name>
>      <param-value>none</param-value>
>         </init-param>
>         <init-param>
>      <param-name>InitConnections</param-name>
>      <param-value>10</param-value>
>         </init-param>
>         <init-param>
>      <param-name>MaxConnections</param-name>
>      <param-value>10</param-value>
>         </init-param>
> 
>     </servlet>

I think its great you are using all of these options, but is this wise
when you are having problems? Why not revert to either ROOT or your own
context off of webapps/? Why not get rid of all the params to simplify
the web.xml file?

> <!--
>     <servlet-mapping>
>         <servlet-name>
>      Census1901
>         </servlet-name>
>         <url-pattern>
>      /Census
>         </url-pattern>
>     </servlet-mapping>
>     -->
> </web-app>

Why mess with servlet mappings? I don't see the need.

> 
> and the relevant lines of the log file under TomCat 4.0.3 are:
> 
> 2002-03-17 14:52:33 StandardHost[localhost]: Installing web
> application at
> context path /Census from URL
> jar:file:D:\jakarta-tomcat-4.0.3\webapps\Census.war!/
> 2002-03-17 14:52:34 WebappLoader[/Census]: Deploying class
> repositories to
> work directory D:\jakarta-tomcat-4.0.3\work\localhost\Census
> 2002-03-17 14:52:34 StandardManager[/Census]: Seeding random number
> generator class java.security.SecureRandom
> 2002-03-17 14:52:34 StandardManager[/Census]: Seeding of random number
> generator has been completed
> 2002-03-17 14:52:34 StandardWrapper[/Census:default]: Loading
> container
> servlet default
> 2002-03-17 14:52:34 default: init
> 2002-03-17 14:52:34 StandardWrapper[/Census:invoker]: Loading
> container
> servlet invoker
> 2002-03-17 14:52:34 invoker: init
> 2002-03-17 14:52:34 jsp: init
> 2002-03-17 14:52:55
> StandardWrapper[:org.apache.catalina.INVOKER.Census.CensusQuery]:
> Marking
> servlet org.apache.catalina.INVOKER.Census.CensusQuery as unavailable
> 2002-03-17 14:52:55 invoker: Cannot allocate servlet instance for path
> /servlet/Census.CensusQuery
> javax.servlet.ServletException: Wrapper cannot find servlet class
> Census.CensusQuery or a class it depends on

One of the problems with the tomcat documentation is that there are no
servlet invocation examples that use packages.

In the conf/web.xml file the InvokerServlet is mapped to servlet/*.
AFAIK, there is no way to have a "raw servlet" be accessible; you ALWAYS
need to give it a name. Something like:

  <servlet>
    <servlet-name>mycensus</servlet-name>
    <servlet-class>Census.CensusQuery</servlet-class>
  </servlet>

I wouldn't worry too much about mapping this name to something else. As
it stands, this servlet is available at:
http://localhost:8080/Census/servlet/mycensus

I believe you can map this to something nice like this (but don't do
this yet!):
  <servlet-mapping>
    <servlet-name>mycensus</servlet-name>
    <url-pattern>/Census</url-pattern>
  </servlet-mapping>

Make sure to study not just the examples code, but also:
%catalina_home%\webapps\examples\WEB-INF

Once you get things working you might want to look into using Ant.

Good luck Jim.


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to