使用 java EE HttpServletRequest对象获取的
request.getRequestURL();
request.getRequestURI();
request.getContextPath();
request.getServletPath();
request.getPathInfo();
ContextPath配置为hello,ServletPath配置为/*
输出:
URL: http://127.0.0.1:8001/hello/world/5555
URI: /hello/world/5555
contextPath: /hello
servletPath:
pathInfo: /world/5555
1、URL包括 ip地址和端口号
2、URI不包括 ip地址和端口号
3、contextPath是web容器——比如tomcat用来决定调用wabapps下的哪个项目的,因为一个web容器可以部署多个项目
4、servletPath就是我们配置的servlet的映射路径
5、pathInfo是我们配置的servlet的映射路径被通配符代替的部分
具体说明
假如contextPath是hello,servlet映射路径配置不同对servletPath和pathInfo的影响:
(1)servletPath配置为 /world/*,我们访问的地址为 127.0.0.1:8080/hello/world/4444
servletPath: /world
pathInfo: /4444
(2)servletPath配置为 /,我们访问的地址为 127.0.0.1:8080/hello/world/6666
servletPath: /world/6666
pathInfo: null