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

前端 未结 4 1597
礼貌的吻别
礼貌的吻别 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:24

    getPathInfo() gives the extra path information after the URI, used to access your Servlet, where as getRequestURI() gives the complete URI.

    I would have thought they would be different, given a Servlet must be configured with its own URI pattern in the first place; I don't think I've ever served a Servlet from root (/).

    For example if Servlet 'Foo' is mapped to URI '/foo' then I would have thought the URI:

    /foo/path/to/resource
    

    Would result in:

    RequestURI = /foo/path/to/resource
    

    and

    PathInfo = /path/to/resource
    

提交回复
热议问题