What's the difference between getRequestURI and getPathInfo methods in HttpServletRequest?

前端 未结 4 1588
礼貌的吻别
礼貌的吻别 2020-11-27 09:13

I\'m making a simple, very lightweight front-controller. I need to match request paths to different handlers (actions) in order to choose the correct one.

On my loca

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 09:49

    Consider the following servlet conf:

       
            NewServlet
            NewServlet
        
        
            NewServlet
            /NewServlet/*
        
    

    Now, when I hit the URL http://localhost:8084/JSPTemp1/NewServlet/jhi, it will invoke NewServlet as it is mapped with the pattern described above.

    Here:

    getRequestURI() =  /JSPTemp1/NewServlet/jhi
    getPathInfo() = /jhi
    

    We have those ones:

    • getPathInfo()

      returns
      a String, decoded by the web container, specifying extra path information that comes after the servlet path but before the query string in the request URL; or null if the URL does not have any extra path information

    • getRequestURI()

      returns
      a String containing the part of the URL from the protocol name up to the query string

提交回复
热议问题