今天看公司框架的源码时,看到路径的问题,不是很清楚,到底哪个是哪个,就自己测了一下:
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println("getRequestURL: " + request.getRequestURL());
System.out.println("getRequestURI: " + request.getRequestURI());
System.out.println("getScheme: " + request.getScheme());
System.out.println("getServerName: " + request.getServerName());
System.out.println("getServerPort: " + request.getServerPort());
System.out.println("getContextPath: " + request.getContextPath());
System.out.println("getServletPath: " + request.getServletPath());
}
然后访问,结果如下:
getRequestURL: http://localhost:8080/TestServlet/Test
getRequestURI: /TestServlet/Test
getScheme: http
getServerName: localhost
getServerPort: 8080
getContextPath: /TestServlet
getServletPath: /Test