HttpServletRequest中getRequestURI和getPathInfo方法之间的区别是什么? [英] What's the difference between getRequestURI and getPathInfo methods in HttpServletRequest?

查看:377
本文介绍了HttpServletRequest中getRequestURI和getPathInfo方法之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单,非常轻巧的前置控制器。我需要将请求路径与不同的处理程序(操作)匹配,以便选择正确的处理程序。

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.

在我的本地计算机上 HttpServletRequest.getPathInfo() HttpServletRequest.getRequestURI() 返回相同的结果。但我不确定它们会在生产环境中返回什么。

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方法之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆