如何区分:Request中getContextPath、getServletPath、getRequestURI、request.getRealPath

假定你的web application 名称为Web_day19

你在浏览器中输入请求路径:http://localhost:8184/Web_day19/userServlet?method=getUser


System.out.println("request.getContextPath() :  "+request.getContextPath() );

打印结果:request.getContextPath() : /Web_day19


System.out.println("request.getServletPath() :  " + request.getServletPath());

打印结果:request.getServletPath() : /userServlet


System.out.println(" request.getRequestURI() :  " + request.getRequestURI() );

打印结果:request.getRequestURI() :  /Web_day19/userServlet


System.out.println("request.getRealPath("/") :  "+ request.getRealPath("/") );

打印结果:

request.getRealPath("/") :      D:\javastudy\javaWeb\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Web_day19\










你可能感兴趣的:(如何区分:Request中getContextPath、getServletPath、getRequestURI、request.getRealPath)