我有这样的结构:
WebContent
resources
components
top.xhtml
company
about_us.xhtml
index.xhtml
top.xhtml
是一个组件,用于index.xthml
和about_us.xhtml
中。
top.xhtml
<ul>
<li><a href="index.xhtml">Home</a></li>
<li><a href="company/about_us.xhtml">About us</a></li>
...
</ul>
所以我的问题是,当当前页面是index.xhtml
时,该组件会正确生成URL,但当当前页面是about_us.xhtml
时,它会生成错误的URL。我不能使用相对路径,因为这也会生成错误的URL。我认为这是因为该组件基于*.xhtml
页面的当前路径。
我找到的唯一解决方法是:
<ul>
<li><a href="${pageContext.request.contextPath}/webname/index.xhtml">Home</a></li>
<li><a href="${pageContext.request.contextPath}/webname/about_us.xhtml">About us</a></li>
...
</ul>
但我认为这并不算是“优雅”的。有什么想法吗?
scope="request"
。 - BalusC