问题描述
我正在制作一个简单,非常轻巧的前置控制器。我需要将请求路径与不同的处理程序(操作)匹配,以便选择正确的处理程序。
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 local machine HttpServletRequest.getPathInfo()
and HttpServletRequest.getRequestURI()
return the same results. But I'm not sure what will they return in the production environment.
那么,这些方法与我应该选择的方法有什么区别?
So, what's the difference between these method and what should I choose?
推荐答案
getPathInfo()
在URI之后提供用于访问Servlet的额外路径信息,其中 getRequestURI()
给出了完整的URI。
getPathInfo()
gives the extra path information after the URI, used to access your Servlet, where as getRequestURI()
gives the complete URI.
考虑到Servlet,我认为它们会有所不同必须首先配置自己的URI模式;我认为我从来没有从root服务过Servlet(/)。
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 (/).
例如,如果Servlet'Foo'映射到URI'/ foo'那么我会想到URI:
For example if Servlet 'Foo' is mapped to URI '/foo' then I would have thought the URI:
/foo/path/to/resource
会导致:
RequestURI = /foo/path/to/resource
和
PathInfo = /path/to/resource
这篇关于HttpServletRequest中getRequestURI和getPathInfo方法之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!