System.out.println("contextPath:"+req.getContextPath());
System.out.println("servletPath:"+req.getServletPath());
System.out.println("requestURI:"+req.getRequestURI());
System.out.println("requestURL:"+req.getRequestURL());
输出结果如下:
contextPath:/test
servletPath:/findEmp
requestURI:/test/findEmp
requestURL:http://localhost:8080/test/findEmp