一,Servlet注册
1,在自定义Servlet类上加上@WebServlet(urlPatterns = {"/myServlet"})或者@WebServlet("/myServlet")注解两种写法都可以。
"/myServlet",是我们访问的Servlet的路径。如:http://localhost:8081/myServlet
@WebServlet(urlPatterns = {"/myServlet"})
//@WebServlet("/myServlet")
public class MyServlet extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter pw = resp.getWriter();
pw.print("zu-cs-a");
pw.close();
}
}
2,在启动类上加上@ServletComponentScan(basePackageClasses = {MyServlet.class})或者@S