为什么request-uri包含默认应用程序的上下文路径?

时间:2013-08-23 16:05:32

标签: java-ee servlets glassfish-3 contextroot

将应用程序App设置为默认应用程序将在没有上下文路径的URL中调用HttpServletRequest.getContextPath()时导致空的上下文路径值。

使用浏览器栏中的以下网址请求网站(否/App!):/foo/bar.xhtml

将导致以下值:

HttpServletRequest.getContextPath() =“”
HttpServletRequest.getServletPath() =“/ foo / bar.xhtml”
HttpServletRequest.getRequestURI() =“/ App / foo / bar.xhtml”

检索request-uri时是否应该删除/App


从uri中删除上下文路径的以下代码行(在许多问题中使用)将不再起作用:

request.getRequestURI().substring(request.getContextPath().length());

或者应该安全地替换为:?

request.getContextPath() + request.getServletPath()

在Glassfish 3.1.2上使用mojarra 2.1.23

Glassfish设置:
申请App - 背景根:/App
虚拟服务器 - 默认Web模块:App

这样我就可以从网址中省略/App

0 个答案:

没有答案