HttpServletRequest.getContextPath()

如果浏览器中输入请求路径:

http://localhost:8080/alan/home/index.html
则执行下面向行代码后打印出如下结果:

1、 log.info(request.getContextPath());

打印结果:/alan
2、log.info(request.getServletPath());

打印结果:home/index.html
3、 log.info(request.getRequestURI());

打印结果:/alan/home/index.html
4、 System.out.println(request.getRealPath(“/”));
E:\workspace\alan\src\main\webapp\

你可能感兴趣的:(java)