You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Anthony Dell'Anno <an...@yahoo.com.INVALID> on 2023/01/10 18:58:23 UTC

Tomcat 10.1.4 HTTP Status 404 and 500 Help

Good afternoon, 
    I'm trying to run my first servlet on Tomcat, and am continually getting an HTTP Status 404 (I've also gotten 500 previously, with the root cause being an apparent compiler mismatch (it would say that it's being compiled by version 63.0, which is Java 19, but that the latest version that was currently accepted was version 59.0, or Java 15), but then after upgrading to JDK 19, changing the JAVA_HOME variable and trying to run, it would still give me the same error)?

    I have my Servlet, called HelloWorldServlet, located in the "C:\apache-tomcat-10.1.4\webapps\ROOT\WEB-INF\classes\" directory, with the web.xml file being located outside of the classes folder, directly inside of the WEB-INF folder.
    I've included both files. StackOverflow wasn't much help as of yet, so I'm hoping that the Tomcat Users community can help me solve this so that I can continue learning servlets. I'm working on building my own software  company.

Any help is appreciated.
Thank you very much,
Anthony Dell'Anno

Re: Tomcat 10.1.4 HTTP Status 404 and 500 Help

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Anthony,

On 1/10/23 13:58, Anthony Dell'Anno wrote:
> I'm trying to run my first servlet on Tomcat

Welcome!

> and am continually getting an HTTP Status 404 (I've also gotten 500
> previously, with the root cause being an apparent compiler mismatch
> (it would say that it's being compiled by version 63.0, which is Java
> 19, but that the latest version that was currently accepted was
> version 59.0, or Java 15), but then after upgrading to JDK 19,
> changing the JAVA_HOME variable and trying to run, it would still
> give me the same error)?

Any error like "Unsupported class version 63.0" or similar will be due 
to a JVM mismatch. There are three ways to correct this:

1. Compile with an earlier JVM
2. Run with a later JVM
3. Specify the target JVM with the compiler. This can be done with the 
"-target" compiler switch in modern compilers

> I have my Servlet, called HelloWorldServlet, located in the 
> "C:\apache-tomcat-10.1.4\webapps\ROOT\WEB-INF\classes\" directory

This isn't a good choice, but will work. I can get back to this, later. 
Is your servlet compiled into a .class file, or do you have a .java file 
in that directory (or both, which is fine)?

> with the web.xml file being located outside of the classes folder,
> directly inside of the WEB-INF folder.

That's where it belongs. The "ROOT" directory contains the entire web 
application, and WEB-INF is a special directory which can contain:

classes/**/*.class [classes, usually your application]
lib/*.jar [libraries, usually from elsewhere]
web.xml [the deployment descriptor]

> I've included both files. StackOverflow wasn't much help as of yet, 
The mailing list often strips attachments, but your plain-text 
attachment made it through. It's much less helpful as an attachment than 
if it were inline, so I'm going to post it here so I can comment on it, 
and also so others can read it without having to detach it:

(I've performed some light editing, which I hope you'll understand.)

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Declare the XML version and encoding...open the document-->
<web-app>
   <!-- Declare a web-app document-->
   <servlet>
     <!--Give the servlet's information-->
     <servlet-name>HelloWorldServlet</servlet-name>
     <servlet-class>webapps.HelloXXXServlet</servlet-class>
   </servlet>

   <servlet-mapping>
     <servlet-name>HelloWorldServlet</servlet-name>
     <!--Provide the servlet name-->
     <url-pattern>/HelloWorld</url-pattern>
     <!--Provide the servlet URL pattern-->
   </servlet-mapping>
</web-app>
<!-- Close the web-app document-->


What is the name of the servlet class itself? You said you have a file 
in WEB-INF/classes called HelloWorldServlet. If that's the class name, 
then it should be in the file HelloWorldServlet.class. In your 
configuration, you have servlet.HelloXXXServlet which is definitely wrong.

If your class name is actually HelloXXXServlet, then you need:

   <!-- Declare a web-app document-->
   <servlet>
     <!--Give the servlet's information-->
     <servlet-name>HelloWorldServlet</servlet-name>
     <servlet-class>HelloXXXServlet</servlet-class>
   </servlet>

The servlet class needs to be the "fully qualified name" of the class, 
which will be the package name (which is nothing in your case) followed 
by a period (if it's in a package, which it isn't) followed by the short 
name of the class (HelloXXXServlet).

The "webapps." was completely incorrect, and it's not clear to me 
exactly what the class name actually is, but I think you should be able 
to get it from here.

The <servlet-name> is something you can make-up and is only used within 
web.xml for the purposes of defining a <servlet> and then mapping it 
later in <servlet-mapping> (and other things, actually, but you aren't 
working with any of those quite yet).

Back to the "don't put your files into WEB-INF/classes" comment I made 
above: it's a good idea to put all of your code into "packages". In 
Java, that means:

1. Putting your class source e.g. HelloXXXServlet.java into a directory 
which matches the package. So if your package will be 
"anthony.dellanno", then you need to have your file in 
src/anthony/dellanno/HelloXXXServlet.java. When compiled, this file 
needs to go into WEB-INF/classes/anthony/dellanno/HelloXXXSServlet.class

2. In your .java file, you need to add at this at the top of the file:

     package anthony.dellanno;

Once you do that, you'll change the "fully qualified class name" in 
web.xml to this:

   <servlet>
     <servlet-name>HelloWorldServlet</servlet-name>
     <servlet-class>anthony.dellanno.HelloXXXServlet</servlet-class>
   </servlet>

And everything else is the same.

> so I'm hoping that the Tomcat Users community can help me solve this
> so that I can continue learning servlets. I'm working on building my
> own software  company.
I highly recommend that anyone working with Java Servlets actually read 
the Java Servlet Specification -- whatever version makes sense for you 
to read. Almost any of them would be good, since there is little change 
between versions for the most part.

Nick Williams wrote a comprehensive (and I mean comprehensive!) book in 
2014 which – despite its age (9 years ago) – is still entirely relevant. 
It's called Professional Java for Web Applications. It guides you 
through these basics and goes all the way up through databases, 
WebSocket, and using the Spring Framework (which he favors in the book; 
other frameworks are available as well).

You can also probably find something similar as your local library if 
you don't want to pay $50 for a dead tree that takes up space on your 
shelf forever.

Hope that helps,
-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 10.1.4 HTTP Status 404 and 500 Help

Posted by John Barrow <jb...@gmail.com>.
Mark,

Thanks for your corrections. I have updated my internal "How to" guide that
I created when I first used Tomcat to build my servlets and it appears that
some of my deductions from that initial research and "getting it to work"
were misguided.

John

On Wed, 11 Jan 2023, 09:28 Mark Thomas, <ma...@apache.org> wrote:

>
>
> On 10/01/2023 22:34, John Barrow wrote:
> > Hi Anthony,
> >
> > Not an expert, but have managed to deploy simple servlets. A couple of
> > observations, not sure why using ROOT, you should have your own folder
> for
> > your application (e.g. myFirstApp\...).
>
> Not true. ROOT is an acceptable option here.
>
> > Also, I have found that the main app folder (e.g. myFirstApp) must start
> > with a lowercase letter (I don't know reason for this but have it in my
> > notes) otherwise the servlets won't be found when accessing them through
> a
> > browser.
>
> Also not true. You may be mixing the rules for Java package names with
> those for context paths.
>
> > Finally, the default install for TomCat has several example servlets
> > already written so check that they work first and then take the sources
> and
> > clone them, using them as a guide for your own servlets.
> >
> > John
> >
> > PS: Probably worth reviewing what file names you use (see your
> webapps.xml
> > file) when making public requests so as not to inadvertently offend
> anyone.
>
> +1
>
> Mark
>
> >
> > On Tue, 10 Jan 2023, 18:59 Anthony Dell'Anno,
> > <an...@yahoo.com.invalid> wrote:
> >
> >> Good afternoon,
> >>
> >>      I'm trying to run my first servlet on Tomcat, and am continually
> >> getting an HTTP Status 404 (I've also gotten 500 previously, with the
> root
> >> cause being an apparent compiler mismatch (it would say that it's being
> >> compiled by version 63.0, which is Java 19, but that the latest version
> >> that was currently accepted was version 59.0, or Java 15), but then
> after
> >> upgrading to JDK 19, changing the JAVA_HOME variable and trying to run,
> it
> >> would still give me the same error)?
> >>
> >>      I have my Servlet, called HelloWorldServlet, located in the
> >> "C:\apache-tomcat-10.1.4\webapps\ROOT\WEB-INF\classes\" directory, with
> the
> >> web.xml file being located outside of the classes folder, directly
> inside
> >> of the WEB-INF folder.
> >>
> >>      I've included both files. StackOverflow wasn't much help as of
> yet, so
> >> I'm hoping that the Tomcat Users community can help me solve this so
> that I
> >> can continue learning servlets. I'm working on building my own software
> >> company.
> >>
> >> Any help is appreciated.
> >>
> >> Thank you very much,
> >>
> >> Anthony Dell'Anno
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Tomcat 10.1.4 HTTP Status 404 and 500 Help

Posted by Mark Thomas <ma...@apache.org>.

On 10/01/2023 22:34, John Barrow wrote:
> Hi Anthony,
> 
> Not an expert, but have managed to deploy simple servlets. A couple of
> observations, not sure why using ROOT, you should have your own folder for
> your application (e.g. myFirstApp\...).

Not true. ROOT is an acceptable option here.

> Also, I have found that the main app folder (e.g. myFirstApp) must start
> with a lowercase letter (I don't know reason for this but have it in my
> notes) otherwise the servlets won't be found when accessing them through a
> browser.

Also not true. You may be mixing the rules for Java package names with 
those for context paths.

> Finally, the default install for TomCat has several example servlets
> already written so check that they work first and then take the sources and
> clone them, using them as a guide for your own servlets.
> 
> John
> 
> PS: Probably worth reviewing what file names you use (see your webapps.xml
> file) when making public requests so as not to inadvertently offend anyone.

+1

Mark

> 
> On Tue, 10 Jan 2023, 18:59 Anthony Dell'Anno,
> <an...@yahoo.com.invalid> wrote:
> 
>> Good afternoon,
>>
>>      I'm trying to run my first servlet on Tomcat, and am continually
>> getting an HTTP Status 404 (I've also gotten 500 previously, with the root
>> cause being an apparent compiler mismatch (it would say that it's being
>> compiled by version 63.0, which is Java 19, but that the latest version
>> that was currently accepted was version 59.0, or Java 15), but then after
>> upgrading to JDK 19, changing the JAVA_HOME variable and trying to run, it
>> would still give me the same error)?
>>
>>      I have my Servlet, called HelloWorldServlet, located in the
>> "C:\apache-tomcat-10.1.4\webapps\ROOT\WEB-INF\classes\" directory, with the
>> web.xml file being located outside of the classes folder, directly inside
>> of the WEB-INF folder.
>>
>>      I've included both files. StackOverflow wasn't much help as of yet, so
>> I'm hoping that the Tomcat Users community can help me solve this so that I
>> can continue learning servlets. I'm working on building my own software
>> company.
>>
>> Any help is appreciated.
>>
>> Thank you very much,
>>
>> Anthony Dell'Anno
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 10.1.4 HTTP Status 404 and 500 Help

Posted by John Barrow <jb...@gmail.com>.
Hi Anthony,

Not an expert, but have managed to deploy simple servlets. A couple of
observations, not sure why using ROOT, you should have your own folder for
your application (e.g. myFirstApp\...).

Also, I have found that the main app folder (e.g. myFirstApp) must start
with a lowercase letter (I don't know reason for this but have it in my
notes) otherwise the servlets won't be found when accessing them through a
browser.

Finally, the default install for TomCat has several example servlets
already written so check that they work first and then take the sources and
clone them, using them as a guide for your own servlets.

John

PS: Probably worth reviewing what file names you use (see your webapps.xml
file) when making public requests so as not to inadvertently offend anyone.

On Tue, 10 Jan 2023, 18:59 Anthony Dell'Anno,
<an...@yahoo.com.invalid> wrote:

> Good afternoon,
>
>     I'm trying to run my first servlet on Tomcat, and am continually
> getting an HTTP Status 404 (I've also gotten 500 previously, with the root
> cause being an apparent compiler mismatch (it would say that it's being
> compiled by version 63.0, which is Java 19, but that the latest version
> that was currently accepted was version 59.0, or Java 15), but then after
> upgrading to JDK 19, changing the JAVA_HOME variable and trying to run, it
> would still give me the same error)?
>
>     I have my Servlet, called HelloWorldServlet, located in the
> "C:\apache-tomcat-10.1.4\webapps\ROOT\WEB-INF\classes\" directory, with the
> web.xml file being located outside of the classes folder, directly inside
> of the WEB-INF folder.
>
>     I've included both files. StackOverflow wasn't much help as of yet, so
> I'm hoping that the Tomcat Users community can help me solve this so that I
> can continue learning servlets. I'm working on building my own software
> company.
>
> Any help is appreciated.
>
> Thank you very much,
>
> Anthony Dell'Anno
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org