wood burning stoves 2.0*
The moose likes Tomcat and the fly likes Tomcat 5 - 404 Error Cannot Find Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat 5 - 404 Error Cannot Find Servlet" Watch "Tomcat 5 - 404 Error Cannot Find Servlet" New topic
Author

Tomcat 5 - 404 Error Cannot Find Servlet

Mark Patrick
Ranch Hand

Joined: Feb 22, 2004
Posts: 51
Hi Ya'll,

I'm trying to deploy a webapp to Tomcat 5.0.19 and am having trouble finding the servlets after deployed. HTML files are found properly, but clicking submit generates an HTTP Status 404 -/SkiClub/LoginServlet error.

I deployed the app by including SkiClub.war to the webapps directory and started tomcat. The WAR was automatically expanded properly.

Following is the directory structure.

webapps\SkiClub - Contains all html and jsp's
webapps\SkiClub\WEBINF - Contains web.xml and classes directory
webapps\SkiClub\WEBINF\classes\com\nearhills\servlets - Contains all servlets (including LoginServlet listed above)

The Login html Form Action is set to "/SkiClub/LoginServlet"

Here is an exerpt from my web.xml file for these servlet


I have also included this Context in server.xml



Any suggestions or help would be great. I'm just learning servlets/jsp and all this application server setup stuff is really confusing.


Mark Patrick<br />SCJP 1.4
Mark Patrick
Ranch Hand

Joined: Feb 22, 2004
Posts: 51
PS... This worked when all the files were in the ROOT.

Thanks.
none oftheabove
Greenhorn

Joined: Jul 17, 2004
Posts: 6


i'm in the same boat...i think being "out of the loop" is part of the punishment for not contributing to the project

i've been using Tomcat 4 for over three years and i think it's great - quite certain that version 5 is only an improvement

however, i recall the utter insanity of figuring out the servlet deployment the first time so i was reluctant to begin the frustration all over again

you've got me beat in that i can't see any servlet at all, ever (even within ROOT)

i'm doing some reading, though, and it looks like modifying your CLASSPATH variable might help (if your code uses packages); if this is the problem then you should probably see a loader exception in the Tomcat system window

i'm sure that you've seen this site by now: http://www.coreservlets.com/Apache-Tomcat-Tutorial/

any hints that you can provide would be appreciated
none oftheabove
Greenhorn

Joined: Jul 17, 2004
Posts: 6
OK, now we're even...i can see the servlets when placed within the ROOT deployment area

i understand your objective and i thought that i wanted to do the same thing (different webapps directory for each servlet) but it looks like that isn't advised for larger projects

it's the way i've been doing it for years but that's probably because it was the first way i could figure out ("if it's always been done that way, it's probably wrong" - Kettering)

it would appear that there is an additional servlet mapping necessary to accomplish the distinct directory...not sure which web.xml

i have the core servlets book at home - i'll let you know what it has to say
none oftheabove
Greenhorn

Joined: Jul 17, 2004
Posts: 6
update:

i've got the "custom" URL mapping working, now - basically, uninstalled/reinstalled and started from scratch (it's tough to say what i goofed up trying to change random values in the XML files...)

once i had a clean slate, there's nothing more to it than the book says:
(1) make sure the server is stopped (in case it doesn't auto-absorb)
(2) copy your webapp into the [tomcat install dir]\webapps directory
(3) make your [tomcat install dir]\webapps\[your app]\WEB-INF\web.xml resemble the following:

<web-app>
<servlet>
<servlet-name>somename</servlet-name>
<servlet-class>package.servletclass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>somename</servlet-name>
<url-pattern>/othername</url-pattern>
</servlet-mapping>
</web-app>

*your web.xml looks fine aside from the extra /SkiClub in url-pattern

*verified that it does no harm to have servlet-name/pattern/class all the same (i.e. LoginServlet)

*there are NO changes necessary for [tomcat install dir]\conf\server.xml or web.xml (i.e. the tomcat-4-style Context element did not need to be present)

*i noticed that if you can get http:\\[host]\SkiClub to show a DIRECTORY LISTING then you're on the right track

the example from their documentation site just about sums up how simple this process is (click on "To a servlet"): http://jakarta.apache.org/tomcat/tomcat-5.0-doc/appdev/sample/web/
none oftheabove
Greenhorn

Joined: Jul 17, 2004
Posts: 6
update:

i've got the "custom" URL mapping working, now - basically, uninstalled/reinstalled and started from scratch (it's tough to say what i goofed up trying to change random values in the XML files...)

once i had a clean slate, there's nothing more to it than the book says:
(1) make sure the server is stopped (in case it doesn't auto-absorb)
(2) copy your webapp into the [tomcat install dir]\webapps directory
(3) make your [tomcat install dir]\webapps\[your app]\WEB-INF\web.xml resemble the following:

<web-app>
<servlet>
<servlet-name>somename</servlet-name>
<servlet-class>package.servletclass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>somename</servlet-name>
<url-pattern>/othername</url-pattern>
</servlet-mapping>
</web-app>

*your web.xml looks fine aside from the extra /SkiClub in url-pattern

*verified that it does no harm to have servlet-name/pattern/class all the same (i.e. LoginServlet)

*there are NO changes necessary for [tomcat install dir]\conf\server.xml or web.xml (i.e. the tomcat-4-style Context element did not need to be present)

*i noticed that if you can get http:\\[host]\SkiClub to show a DIRECTORY LISTING then you're on the right track

the example from their documentation site just about sums up how simple this process is (click on "To a servlet"): http://jakarta.apache.org/tomcat/tomcat-5.0-doc/appdev/sample/web/
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

"none oftheabove".

Please check our naming policy, and alter your displayed name.

Thanks.


As for some of what you said:

*Leave CLASSPATH utterly alone. It means nothing to Tomcat.
*Different webapps directory for each servlet?? you mean "each webapp" right?
*Tomcat 5.x changed the 'how' of configuration quit a bit. Tomcat 4.x style configuration still works however, so it's still recommended that you have a Context declared. Now with TC5.x, it can be in two different places. I personally would never rely on anything 'automagic'.
* the extra /SkiClub was most likely the only problem.
 
Don't get me started about those stupid light bulbs.
 
subject: Tomcat 5 - 404 Error Cannot Find Servlet