Steps:
①在左侧项目上右击new 然后依次找到 Edit File Templates
②进入Edit File Templates:
刚开始进入是在Files一列,然后点击** Other**
③依次点击 Web ---> Java code templates 就可以看见两种Servlet模板:
**第一行是不带注解的: ↓**
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
#if ($JAVAEE_TYPE == "jakarta")
import jakarta.servlet.*;
import jakarta.servlet.http.*;
#else
import javax.servlet.*;
import javax.servlet.http.*;
#end
import java.io.IOException;
public class ${Class_Name} extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
第二行是带注解的:↓
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
#if ($JAVAEE_TYPE == "jakarta")
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
#else
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
#end
import java.io.IOException;
@WebServlet(name = "${Entity_Name}", value = "/${Entity_Name}")
public class ${Class_Name} extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
④依次点击Files ---> + 号 ---> 设置Name为“Servlet”,Extension为”java“
然后把刚刚复制的模板直接粘贴到红字所在的空白区域
点击Apply即可
标签:
servlet
本文转载自: https://blog.csdn.net/Odyssey_kd/article/details/135963439
版权归原作者 弯路十三郎 所有, 如有侵权,请联系我们删除。
版权归原作者 弯路十三郎 所有, 如有侵权,请联系我们删除。