servlet3.0 注解开发 helloworld
使用编辑器为MyEclipse 版本2018 .9
当前版本
老版本
新建一个Servlet
1 package com.xiaou; 2 3 import java.io.IOException; 4 5 import javax.servlet.ServletException; 6 import javax.servlet.annotation.WebServlet; 7 import javax.servlet.http.HttpServlet; 8 import javax.servlet.http.HttpServletRequest; 9 import javax.servlet.http.HttpServletResponse; 10 11 @WebServlet(name="servlet1",urlPatterns="/helloworld") 12 public class Servlet extends HttpServlet{ 13 14 private static final long serialVersionUID = 1L; 15 16 @Override 17 protected void doGet(HttpServletRequest req, HttpServletResponse resp) 18 throws ServletException, IOException { 19 resp.getWriter().write("helloworld"); 20 } 21 22 @Override 23 protected void doPost(HttpServletRequest req, HttpServletResponse resp) 24 throws ServletException, IOException { 25 this.doGet(req, resp); 26 } 27 28 }
这个就是Servlet注解的QuickStart(快速入门)