2023的idea鼠标右键是没有Servlet,所以需要我们手动添加
一、添加Servlet
1、点击File->Settings
2、展开Editor,单击File and Code Templates,选择Files
3、单击+号,修改Name和File name为Servlet,复制以下代码块粘贴到idea
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/${Class_Name}")
public class ${Class_Name} extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
4、粘贴完点击OK就行了
二、检查添加是否成功(新建Servlet)
1、选中src鼠标右键,单击New->Servlet
2、设置Servler类名
3、完成添加
版权归原作者 灵魂的编符 所有, 如有侵权,请联系我们删除。