1.创建一个类实现Servlet并且重写接口的方法( 二 )


6.现在已经简化了好了,但是每次创建之后要继承还要手写注解,还是不够简单,所以我们配合模板开发
a.打开File->->->File and Code ->Other->Web->Java Code ->Class.java
b.将里面的内容更换成以下内容
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end#parse("File Header.java")@javax.servlet.annotation.WebServlet(urlPatterns = "/${Entity_Name}",name = "${Entity_Name}")public class ${Class_Name} extends javax.servlet.http.HttpServlet {protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {}protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {doPost(request,response);}}
c.创建模板开始写代码
d.创建好的样子
package com.sss.demo;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(urlPatterns = "/DemoServlet5", name = "DemoServlet5")public class DemoServlet5 extends HttpServlet {protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request, response);}}