I\'m trying to get into Java web development but seem to be running into a strange issue with Tomcat and an extremely simple servlet. The catalina log is spewing this every
Are the lines below exactly from your web.xml
? Tomcat finds the servlet mapping that maps /myservlet
to the servlet named "MyServlet
" but complains that it cannot find any servlet definition with that name. Case matters. What you provided looks correct, but double check your web.xml
to make sure the case is correct. Double check the web.xml
where Tomcat is using it, in the directory mywebapp/WEB-INF/web.xml
<servlet>
<servlet-name>MyServlet</servlet-name> <-- Check this name
<servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name> <-- Compare against this name
<url-pattern>/myservlet</url-pattern>
</servlet-mapping>
If that's not it, let us know. But these names are case sensitive.
Could there be a older version of web.xml
lurking around somewhere, without the <servlet>
block?
Perhaps do a find . -type f -name web.xml
(or similar for windows) in tomcat's directories?
Well, given the updated information, it appears that your problem is that the compiler you used for your class is potentially a newer version of the JDK than the one running Tomcat.
Check the JDK version being used to start Tomcat, and then see if you can do something to reconcile the version differences between that and the one you're using to compile your servlet with.
That should clear up your issue.
If the MyServlet class is in a package, you should list it with package-dot-class notation in your servlet-name nodes.
Few hints:
In general, also try to look for more exceptions in the logs.