3.4.1精确匹配
配置路径 : @WebServlet("/ok/zs")
访问 servlet: localhost:8080/servlet/ok/zs
eg
@WebServlet(urlPatterns = "/ok/zs")
public class OkServlet2 extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("okServlet doPost");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("OkServlet2 doGet");
}
}
3.4.2目录匹配
配置路径 : @WebServlet("/ok/*")
访问文件: localhost:8080/servlet/ok/aaa localhost:8080/servlet/ok/bbb
3.4.3扩展名匹配
配置路径 : @WebServlet("*.action")
访问文件: localhost:8080/hsp/zs.action localhost:8080/hsp/ls.action
提示: @WebServlet("/*.action") , 不能带 / , 否则 tomcat 报错
3.4.4任意匹配
配置路径 : @WebServlet("/") @WebServlet("/*")
访问文件: localhost:8080/hsp/aaa localhost:8080/hsp/bbb localhost:8080/hsp/ccc
提醒:/ 和 /*的配置,会匹配所有的请求,这个比较麻烦,要避免
优先级遵守: 精确路径>目录路径>扩展名路径>/*>/