Tomcat is unable to find my Servlet and is throwing exceptions, but why?

前端 未结 5 706
野的像风
野的像风 2021-01-11 18:48

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

相关标签:
5条回答
  • 2021-01-11 19:05

    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.

    0 讨论(0)
  • 2021-01-11 19:12

    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?

    0 讨论(0)
  • 2021-01-11 19:16

    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.

    0 讨论(0)
  • 2021-01-11 19:21

    If the MyServlet class is in a package, you should list it with package-dot-class notation in your servlet-name nodes.

    0 讨论(0)
  • 2021-01-11 19:31

    Few hints:

    • Does your servlet class extend HttpServlet?
    • How about filesystem rights - any possible problem there?
    • Perhaps, try also to move the class to a named package (myservlet.MyServlet)

    In general, also try to look for more exceptions in the logs.

    0 讨论(0)
提交回复
热议问题