欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Eclipse自定义带注解的Servlet模版

程序员文章站 2022-03-25 14:56:13
...

Eclipse自定义带注解的Servlet模版

步骤:

  1. eclipse中的Windows首选项在输入框中输入tem,选择Java中的Templates,点击new新建一个Servlet模版Eclipse自定义带注解的Servlet模版
  2. 自定义模版的代码如下如下:
package ${enclosing_package};
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 @WebServlet("/${primary_type_name}")
public class ${primary_type_name} extends HttpServlet {
 
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().write("hello haohao...");
	}
 
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
  1. 设置截图如下:
    Eclipse自定义带注解的Servlet模版
相关标签: Eclipse