Reputation: 3342
So here are 2 requests:
When the <welcome-file>index.xhtml</welcome-file>
is been set, request 1 is handled by the server as 2.
However, in both cases the request.getRequestURI()
returns the complete URI: someUrl/index.xhtml
.
According to documentation it shouldn't but in most cases it's what we want so it seems fine it does.
I'm working with JSF under JBoss Wildfly (Undertow webservice) and I don't know which one is responsible.
I don't necessarily want to change how it works but I'm looking for a way of getting the original URI as the enduser sees in browser address bar, thus without the index.xhtml
part in case of 1.
To be more precise, I have to get the exact same URL as returned by document.location.href
in JavaScript.
Upvotes: 1
Views: 524
Reputation: 1109292
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();
}
// ...
Upvotes: 3