正如MaVRoSCy说,你可以使用Prettyfaces重写网址。他们的文档非常有用,非常清晰。下面是遵循的步骤(没有Maven依赖关系的方法):
1)根据你的JSF版本下载最新的jar并把它放到你的项目类路径中。
2)添加以下内容web.xml
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
3)WEB-INF
下创建一个文件:pretty-config.xml
将定义你的prettyfaces映射,像这样的:在定义outcome
时
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.0
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.0.xsd">
<url-mapping id="accueil">
<pattern value="/" />
<view-id value="/path-to-yourpage.xhtml" />
</url-mapping>
<url-mapping id="error">
<pattern value="/" />
<view-id value="/tpath-to-yourpage2.xhtml" />
</url-mapping>
</pretty-config>
4)现在你托管的豆类,您应该返回pretty:idOfURLMapping
。例如:pretty:accueil
将重定向到上面第一个定义的页面,通常它会显示http://localhost:8080/PlanificationDrapageWeb/
作为URL。
最后,请注意,只有在功能需求的情况下,您才应该使用它。否则,我会使用没有扩展名的URL作为BalusC提到的(他的方法或者如果你想要高级的Prettyfaces功能)。
编辑
看来Prettyfaces不适合这种情况。对不起,你浪费时间。
现在我会建议另一种可能的解决方案,因为BalusC的答案已被删除。
1)创建会话范围的新的托管bean,我们称之为:PageManagedBean
:
public class PageManagedBean {
private String includedPage = "/pages/accueil.xhtml";
//Setters and getters
}
2)创建主布局页面(Facelets模板):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<ui:insert name="head"></ui:insert>
</h:head>
<h:body>
<div class="pagewidth">
<ui:include src="shared/header.xhtml"/>
<!-- Content -->
<div class="page_content">
<div class="page_content_inner">
<div class="container">
<ui:include id="pageLivre" src="#{pageManagedBean.includedPage}"/>
</div>
</div>
</div>
<div class="page_content_footer"/>
<ui:include src="shared/footer.xhtml"/>
</div>
</h:body>
现在,当你想要更改页面,只需更改PageManagedBean.includedPage值。
什么应用服务器? – MaVRoSCy
我正在使用Glassfish – marouanoviche