我使用Icefaces和JSF,我遇到了这个问题:
我有以下网址:
http://myMappedServer/myApp/followingThings
我想在我的xHtml页面中获取值http://myMappedServer/myApp
如何在不使用托管bean的情况下实现这一目标?
答案 0 :(得分:9)
使用EL:#{request.contextPath}
。
这对于创建导航链接非常有用,可以在主模板中设置Facelets变量:)
<ui:param name="root" value="#{request.contextPath}/" />
更新:not recommended to use the full path available in the app server因为它不能保证与用户访问您应用时使用的网址相同,所以请注意这一点。
但是,如果您真的想要can do that,请使用HttpServletRequest中提供的一些方法来创建这样的字符串:
#{request.scheme}://#{request.serverName}:#{request.serverPort}#{request.contextPath}