获取url直到上下文路径

aik*_*ika 3 url jsf

我使用Icefaces和JSF,我遇到了这个问题:我有以下网址: http://myMappedServer/myApp/followingThings

我想在我的xHtml页面中获取值http://myMappedServer/myApp 如何在不使用托管bean的情况下实现此目的?

Eli*_*les 9

使用EL : #{request.contextPath}.

它对于创建导航链接非常有用,可以在主模板中设置Facelets变量:)

<ui:param name="root" value="#{request.contextPath}/" />
Run Code Online (Sandbox Code Playgroud)

更新:不建议使用可用的完整路径在应用服务器,因为它不能保证用户使用来访问你的应用程序相同的URL,因此,那要小心了.

但是,如果你真的想要,你可以使用HttpServletRequest中的一些方法来创建一个这样的String:

#{request.scheme}://#{request.serverName}:#{request.serverPort}#{request.contextPath}
Run Code Online (Sandbox Code Playgroud)