请求 http://localhost:8080/ServletDemo/abc/../hello;xyz
在ServletDemo的/hello响应函数中,
request.getRequestURI() ---> /ServletDemo/abc/../hello;xyz
request.getRequestURL() ---> http://localhost:8080/ServletDemo/abc/../hello;xyz
request.getContextPath() ---> /ServletDemo
request.getServletPath() ---> /hello
request.getPathInfo() ---> null 其实是除了getContextPath和getServletPath的其他路径部分,是实际路径相对于servlet的配置路径(*通配)多出来的部分
----------------------
所以实际上getRequestURI和getRequestURL用来做路径校验的话是有风险的
网友评论