2012-04-09 103 views
0

我有一些問題與JSF顯示默認網址:JSF 2.0和歡迎,文件

的URL顯示如下:

www.URL.com/PROYECT_NAME/

我希望是這樣的

www.URL.com/PROYECT_NAME/home

我送了歡迎文件是這樣的。

<welcome-file-list> 
    <welcome-file >faces/views/home.xhtml</welcome-file> 
</welcome-file-list> 

所以我真正想要的是,當JSF表示歡迎文件顯示和URL這樣www.URL.com/PROYECT_NAME/home或完整路徑的面孔/視圖/ home.xhtml。

我知道是一個愚蠢的問題,但是我的股票在其

回答

0

這是可能實現使用基於過濾器的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

我希望它有幫助。