Eclipse自定义带注解的Servlet模版
程序员文章站
2022-03-25 14:56:13
...
Eclipse自定义带注解的Servlet模版
步骤:
- eclipse中的Windows首选项在输入框中输入tem,选择Java中的Templates,点击new新建一个Servlet模版
- 自定义模版的代码如下如下:
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);
}
}
- 设置截图如下:
上一篇: 综合架构