The welcome file is been displayed by a forward which is under the server's covers been performed by RequestDispatcher#forward()
. In that case, the original request URI is available as a request attribute with a key as identified by RequestDispatcher#FORWARD_REQUEST_URI
, which is javax.servlet.forward.request_uri
.
So, this should do:
String originalURI = request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
if (originalURI == null) {
originalURI = request.getRequestURI();
}
// ...