Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat 5 - 404 Error Cannot Find Servlet

 
Mark Patrick
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PS... This worked when all the files were in the ROOT.

Thanks.
 
none oftheabove
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic