java.lang.ClassCastException: class cannot be cast to javax.servlet.Servlet

Solution Verified - Updated -

Environment

  • JBoss Enterprise Application Platform (EAP) 6.x

Issue

  • We see the following exception:

    java.lang.ClassCastException: package.className cannot be cast to javax.servlet.Servlet
    

Resolution

  • Ensure any class mapped as a Servlet via annotations or in the application WEB-INF/web.xml extends javax.servlet.http.HttpServlet as noted by the [EE6 tutorials](https://docs.oracle.com/javaee/6/tutorial/doc/bnafu.html

Root Cause

  • A class mapped as a Servlet via annotations or in the application WEB-INF/web.xml does not extend Servlet.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments