出现问题:IDEA右键创建Servlet时,找不到选项
原因分析:IDEA的2023版的已经不支持Servlet了,如果还要使用的话,需要自己创建模板使用
创建模板
右击设置,选择(File and Code Templates),点击“+”
模板命和文件名都命名为:Servlet
,文本内容输入自己需要的固定格式,完成后点击OK。模板源码在下面
完成配置之后,此时右键出现Servlet选项
模板代码
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/${Class_Name}")
public class ${Class_Name} extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.doGet(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.doPost(request, response);
}
}