What is the exact difference between request.getRequestURI() and request.getServletPath()?

sonia wen

request.getRequestURI() contains the context path defined in your server.xml, on the other hand, request.getServletPath() does not contain this path.

For example, in your server.xml, you define:

<Context path="/mywebapp" docBase="D:workmywebapp" debug="0" reloadable="true" /> ;

under the directory d:workmywebapp, you have sub directory WEB-INF and jsps, under the directory d:workmywebappjsps, you save your jsp file, say mytest.jsp. So when you use request.getRequestURI(), the result will be: /mywebapp/jsps/mytest.jsp, the other result using request.getServletPath() will be /jsps/mytest.jsp.