Why does the request-uri contains context-path for default application?

1.5k Views Asked by At

Setting application App as the default application will leads to an empty context-path value when calling HttpServletRequest.getContextPath() from an url without the context-path.

Requesting site using following url in browser-bar (no /App!): /foo/bar.xhtml

will lead to following values:

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

Should /App not be removed when retrieving the request-uri?


The following line of code (which is used in many so-questions) to remove the context-path from the uri won't work anymore:

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

or should this safely be replaced with:?

request.getContextPath() + request.getServletPath()

Using mojarra 2.1.23 on Glassfish 3.1.2

Glassfish settings:
Application App - Context Root: /App
Virtual Server - default web module: App

So that I can omit /App from the URL.

0

There are 0 best solutions below