request.getRequestURL()和request.getRequestURI()

先在拦截器里执行方法看一看结果

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

  结果:

     getRequestURI:/user/index
     getRequestURL:http://localhost/user/index
     getContextPath:
     getServletPath:/user/index

  总结:

    1. request.getRequestURI() 返回除去host(域名或者ip)部分的路径
    2. request.getRequestURL() 返回全路径
    3. request.getContextPath() 返回工程名部分,如果工程映射为/,此处返回则为空
    4. request.getServletPath() 返回除去host和工程名部分的路径

request.getRequestURL()和request.getRequestURI()

上一篇:formdata实现图片上传


下一篇:模拟postman开发的Http请求工具类