1. 通过 Eclipse 创立一个 Servlet 类,将其中的内容批改成本人冀望的模板格局,并复制其内容,例:
package ${enclosing_package};
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* author: bjzhangsz@tedu.cn
* datetime: ${date} ${time}
*/
public class ${primary_type_name} extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {![image](/img/bVbLWib) doGet(request, response);
}
}
2. 点击菜单栏中的 windows–>
3. 在呈现的窗口左侧顺次点击:Java–>Editor–>templates–>(在左边的窗口中) 点击 New…:
4. 呈现的新窗口填写:
5. 替换包门路和类名(作用是在新建 Servlet 生成的 Servlet 模版中应用以后类的包门路和类型)图:
成果:
6. 点击 OK 保留,创立新的 Servlet 文件,测试:
将原有的 Servlet 所有内容删除,并输出 "servlet", 按 "Alt+/" 生成