aika
aika

Reputation: 73

get the url until the context path

I use Icefaces and JSF and I have this problem: I have the following url: http://myMappedServer/myApp/followingThings

I would like to get in my xHtml page the value http://myMappedServer/myApp How can I achieve this without using the managed bean?

Upvotes: 3

Views: 16529

Answers (1)

Elias Dorneles
Elias Dorneles

Reputation: 23806

Use EL: #{request.contextPath}.

It's quite useful for creating navigation links, to set in your main template a Facelets variable :)

<ui:param name="root" value="#{request.contextPath}/" />

UPDATE: It's not recommended to use the full path available in the app server because it's not guaranteed to be the same URL the user is using to access your app, so, beware of that.

If you really want, though, you can do that, using some methods available in HttpServletRequest to create an String like this:

#{request.scheme}://#{request.serverName}:#{request.serverPort}#{request.contextPath}

Upvotes: 9

Related Questions