@WebServlet("/hello")
来标注,并且指明要拦截哪些路径package com.ldc.servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("hello...");
}
}
@WebFilter
注解、注册Listener用@WebListener
注解;如果在注册的时候,需要一些初始化参数,我们就可以用@WebInitParam
注解