這是可能實現使用基於過濾器的servlet等擴展PrettyFaces。
它簡單易用,具有良好的文檔和示例,而是說明你的情況,你可以做這樣的事情:
- 下載prettyfaces.jar並添加到您的類路徑中。通常爲
/WEB-INF/lib
文件夾。
- 將包含URL映射的pretty-config.xml文件添加到
/WEB-INF
文件夾中。
漂亮-config.xml文件中的示例:
<?xml version="1.0" encoding="UTF-8"?>
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.3 http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.3.xsd">
<url-mapping id="home">
<pattern value="/home" />
<view-id value="/home.xhtml" />
</url-mapping>
</pretty-config>
重定向到這個映射從控制器,你應該使用像pretty:
+ url-mapping-id
的字符串。控制器豆的
實施例:
@ManagedBean
@ViewScoped
public class HomeBean
{
public String goHome()
{
return "pretty:home";
}
}
就是這樣。每當您發起請求時,如果PrettyFaces過濾器找到url映射模式/home
,它將顯示視圖ID home.xhtml
,但保留URL爲/home
。漂亮。
此外,作爲建議,對於您的welcome-file-list
,您只能添加index.html
。歡迎的web.xml文件列表標籤的
例子:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
並添加像這樣的index.html文件到您的應用程序根目錄。 index.html文件的
例子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Application</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="0;url=/myapplication/home" />
</head>
<body>
<h3>Loading...</h3>
</body>
</html>
這樣,只要有人請求您的應用程序也將得到快速加載頁面,將被重定向到/home
。
我希望它有幫助。