Java – Tomcat can’t find my servlet and throw an exception, but why?
I tried to get into Java Web development, but it seems to be running into a strange problem with Tomcat and a very simple servlet Whenever I try to load the application, Catalina logs play:
Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an unkNown servlet name MyServlet at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:2393) at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:2373) ... 40 more Mar 4,2009 10:37:58 AM org.apache.catalina.startup.ContextConfig applicationWebConfig SEVERE: Parse error in application web.xml file at jndi:/localhost/mywebapp/WEB-INF/web.xml java.lang.IllegalArgumentException: Servlet mapping specifies an unkNown servlet name MyServlet
Decent feeling can't seem to find my servlet However, the servlet seems to be in the right place X-4545 X-4545 X-4545 X- 200 X- 200 X- 200 200 X- 200 200 X-
As a reference, this is the web XML file:
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <description>My first web app in Java.</description> <display-name>My Web App</display-name> <servlet> <servlet-name>MyServlet</servlet-name> <servlet-class>MyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>MyServlet</servlet-name> <url-pattern>/myservlet</url-pattern> </servlet-mapping> </web-app>
200 new x-45 flag, new new flag, new flag, new 200 flag, new 200 flag, new flag, new flag, new flag, new flag, new flag, new flag, new flag, new flag, new flag, new flag, new flag, new flag, new flag, new flag in Java, what is a bare metal web application like, and what components do I lack?
to update
To be absolutely sure it wasn't some kind of tool, I started a new copy of Tomcat and tried again Once you do this, this begins to appear in the log file:
SEVERE: Error deploying web application archive mywebapp.war java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class MyServlet)
I took mine The class file is dumped to the myservlet class and repackaged with - target 1.5 War, everything is perfect
Thank you very much for your help! A good lesson in troubleshooting won't hurt anyone
Solution
So given the updated information, it seems that your problem is that the compiler you use for your class may be a JDK that runs a newer version of Tomcat
Check the JDK version used to start Tomcat and see if you can do something to reconcile the differences from the version you are using to compile the servlet
This should clear up your problem