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和工程名部分的路径
posted @ 2020-07-02 12:34  余情呀  阅读(4647)  评论(0编辑  收藏  举报