1. 程式人生 > >request.getRequestURL()和request.getRequestURI()的區別

request.getRequestURL()和request.getRequestURI()的區別

request.getRequestURL() 返回全路徑

request.getRequestURI() 返回除去host(域名或者ip)部分的路徑

request.getContextPath() 返回工程名部分,如果工程對映為/,此處返回則為空

request.getServletPath() 返回除去host和工程名部分的路徑

例如:

request.getRequestURL() http://localhost:8080/jqueryLearn/resources/request.jsp  request.getRequestURI() /jqueryLearn/resources/request.jsp request.getContextPath()/jqueryLearn  request.getServletPath()/resources/request.jsp