浏览器向tomcat发出http请求:http://localhost:8080/web项目名/servlet的url-pattern(与在login.jsp的form表单中的action=“&&&”,&&&的名称需要与servlet配置中的url-pattern一致,主要是产生映射)
假设web application的名称为test,需要在浏览器中输入请求路径:http://localhost:8080/test/login.jsp 或 http://localhost:8080/test/url-pattern
则执行下列代码后打印出如下结果:
1、System.out.println(request.getRequestURI());
打印结果:/test/login.jsp
2、System.out.println(request.getRequestURL());
打印结果:http://localhost:8080/test/login.jsp
3、 System.out.println(request.getContextPath());
打印结果:/test
4、System.out.println(request.getServletPath());
打印结果:/login.jsp