dimanche 28 février 2021

cannot be cast to jakarta.servlet.Servlet [duplicate]

I am studying Java Web. I added the dependency and created a servlet class. After starting tomcat, I received the errors that this is not a servlet and cannot be cast to jakarta.servlet.Servlet. Could you help me find what the root cause is?

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("hello servlet");
        PrintWriter writer = resp.getWriter();
        writer.print("hello,servlet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}



Aucun commentaire:

Enregistrer un commentaire