本文为自用文章,也可做参考使用。
IDEA 2022
See the document.
Servlet & Tomcat 10
https://stackoverflow.com/questions/9193228/compile-error-package-javax-servlet-does-not-exist
import jakarta.servlet.*;
import jakarta.servlet.http.*;
Classes
import javax.servlet.annotation.WebServlet; // annotation for "注解"
import javax.servlet.http.HttpServlet; // for Extends
import javax.servlet.http.HttpServletRequest; // for type
import javax.servlet.http.HttpServletResponse;// for type
// following for the throws
import javax.servlet.ServletException;
import java.io.IOException;
Or...
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
Override methods
public class alcohol extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setCharacterEncoding("utf-8");
response.getWriter().write("Do you wanna an alcohol?");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//doGet(request, response);
response.setCharacterEncoding("utf-8");
response.getWriter().write("Do you wanna a post-type alcohol?");
}
}