添加Servlet模板

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: [email protected]
 * 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-->
image
6.点击OK保存,创建新的Servlet文件,测试:

    将原有的Servlet所有内容删除,并输入"servlet",按"Alt+/"生成

你可能感兴趣的:(servlet)