我有这个结构:
WebContent
resources
components
top.xhtml
company
about_us.xhtml
index.xhtml
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,当当前页面是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>
Run Code Online (Sandbox Code Playgroud)
但我认为根本不是"优雅".有任何想法吗?