Issue
G:\demo3\src\main\java\com\example\demo3>javac HelloServlet.java -classpath "C:\Program Files\Apache Software Foundation\Tomcat 10.0\lib\servlet-api.jar"
HelloServlet.java:8: error: cannot find symbol
public class HelloServlet extends GenericServlet{
^
symbol: class GenericServlet
HelloServlet.java:10: error: cannot find symbol
public void service(ServletRequest servletRequest, ServletResponse servletResponse)
^
symbol: class ServletRequest
location: class HelloServlet
HelloServlet.java:10: error: cannot find symbol
public void service(ServletRequest servletRequest, ServletResponse servletResponse)
^
symbol: class ServletResponse
location: class HelloServlet
HelloServlet.java:11: error: cannot find symbol
throws ServletException, IOException {
^
symbol: class ServletException
location: class HelloServlet
HelloServlet.java:3: error: package javax.servlet does not exist
import javax.servlet.*;
^
HelloServlet.java:9: error: method does not override or implement a method from a supertype
@Override
^
6 errors
what iam doing wrong? CLASSPATH created to servlet-api.jar file btw enter image description here
Solution
Tomcat 10 is using the new jakarta.*
namespace for the servlet packages. You are importing the old javax.servlet.*
. Just replace javax.servlet.
with jakarta.servlet.
and compilation should work.
Answered By - Nikos Paraskevopoulos
Answer Checked By - Timothy Miller (JavaFixing Admin)