Tomcat 10.x and higher require Jakarta namespaces versions of the Servlet
specifications.
Tomcat 9.x is the last Tomcat support javax.servlet namespaces.

Refer to the Which Version page for Tomcat for details:
https://tomcat.apache.org/whichversion.html

On Tue, Nov 21, 2023 at 3:30 PM Campbell, Lance <la...@illinois.edu> wrote:

> I am migrating from Java 8 tomcat 9 to Java 11 tomcat 10.1 .
>
> I am getting a cast class exception when trying to access my login
> servlet. In my servlets I am using these packages:
>
>
> import javax.servlet.ServletException;
>
> import javax.servlet.http.HttpServlet;
>
> import javax.servlet.http.HttpServletRequest;
>
> import javax.servlet.http.HttpServletResponse;
>
>
>   1.  Does either Java 11 or Tomcat 10.1 require that I use
> Jakarta.servlet.* packages instead of javax.servlet.*?
>   2.  If that is the case, then what is specifically requiring this? Is it
> Java 11 or Tomcat 10.1 or both?
>
> My servlet is getting this error:
>
> 21-Nov-2023 14:14:52.768 INFO [main]
> org.apache.catalina.core.ApplicationContext.log Marking servlet
> [LoginServlet] as unavailable
> 21-Nov-2023 14:14:52.769 SEVERE [main]
> org.apache.catalina.core.StandardContext.loadOnStartup Servlet
> [LoginServlet] in web application [] threw load() exception
>         java.lang.ClassCastException: class xyz.servlet.LoginServlet
> cannot be cast to class jakarta.servlet.Servlet
> (xyz.servlet.LoginServlet is in unnamed module of loader
> org.apache.catalina.loader.ParallelWebappClassLoader
> @2ccca26f; jakarta.servlet.Servlet is in unnamed module of loader
> java.net.URLClassLoader @63e2203c)
>
> Thanks,
>
> Lance
>

Reply via email to